note 78142 deleted from language.variables.predefined by nlopess

From: Date: Sat, 29 Sep 2007 22:57:53 +0000
Subject: note 78142 deleted from language.variables.predefined by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130937@lists.php.net to get a copy of this message
Note Submitter: fabrizio at bibivu dot com ---- Here is my function optimized some more... <?php /** * This function will fill the _GET global variable * * @access private * @param void * @return void */ private function _fill_GET(){ /** * This function converts info.php/a/1/b/2/c?d=4 TO * array ( [d] => 4 [a] => 1 [b] => 2 [c] => array ( [d] => 4 ) ) * try it with this URL (all in one line): http://devel.bibivu.com/index.php/test/1/te st/2/test/3/test?k=4/test1?test=5/////index.php/test **/ $SELF = pathinfo(__FILE__, PATHINFO_BASENAME); $_GET = NULL; $request_uri = $_SERVER['REQUEST_URI']; //remove index $query_string = preg_replace('/^\/'.$SELF.'/','',$request_uri); if($query_string != '' && $query_string != '/'){ //Split it out. $tmp = explode('/',$query_string); //Remove first empty item unset($tmp[0]); //Loop through and append it into the $_GET superglobal. for($i=1;$i<=count($tmp);$i+=2){ if(strpos($tmp[$i],'?')!==false){ $tmp1 = explode('?',$tmp[$i]); parse_str(isset($tmp1[1])?$tmp1[1]:'',$value); $i--; if(isset($_GET[$tmp1[0]])){ if(!is_array($_GET[$tmp1[0]])){ $_GET[$tmp1[0]] = array($_GET[$tmp1[0]]); } $_GET[$tmp1[0]][] = $value; } else { $_GET[$tmp1[0]] = $value; } } else { $value = isset($tmp[$i+1])?$tmp[$i+1]:''; if(isset($_GET[$tmp[$i]])){ if(!is_array($_GET[$tmp[$i]])){ $_GET[$tmp[$i]] = array($_GET[$tmp[$i]]); } $_GET[$tmp[$i]][] = $value; } else { $_GET[$tmp[$i]] = $value; } } } } } ?>

« previous php.notes (#130937) next »