LotGDocker/lotgd-web/lotgd/lib/arraytourl.php
2020-08-17 19:16:42 -04:00

55 lines
1.3 KiB
PHP
Executable File

<?php
// addnews ready
// translator ready
// mail ready
/**
* URL <-> array functions
*
* @copyright Copyright © 2002-2005, Eric Stevens & JT Traub, © 2006-2009, Dragonprime Development Team
* @version Lotgd 1.1.2 DragonPrime Edition
* @package Core
* @subpackage Library
* @license http://creativecommons.org/licenses/by-nc-sa/2.0/legalcode
*/
/**
* Turns an array into an URL argument string
*
* Takes an array and encodes it in key=val&key=val form.
* Does not add starting ?
*
* @param array $array The array to turn into an URL
* @return string The URL
*/
function arraytourl($array){
//takes an array and encodes it in key=val&key=val form.
$url="";
$i=0;
foreach($array as $key=>$val){
if ($i>0) $url.="&";
$i++;
$url.=rawurlencode($key)."=".rawurlencode($val);
}
return $url;
}
/**
* Takes an array and returns its arguments in an array
*
* @param string $url The URL
* @return array The arguments from the URL
*/
function urltoarray($url){
//takes a URL and returns its arguments in array form.
if (strpos($url,"?")!==false){
$url = substr($array,strpos($url,"?")+1);
}
$a = explode("&",$url);
$array = array();
foreach($a as $val){
$b = explode("=",$val);
$array[urldecode($b[0])] = urldecode($b[1]);
}
return $array;
}
?>