This is my own version that I was using for php <=4, hope that will help someone
this can accomplish a few things:
if called w/o parameters will return the current link
if called with the first parameter like:
param1=a¶m2=b
will return a link with the query string containing ONLY what is passed.
if called with the first parameter like:
¶m1=a¶m2=b
will return a string with the current query string plus what is passed to the function
this function uses by default PHP_SELF, but if you pass the page will create the link with what you pass.
If pass secure(boolean), will create an https or http.
$url will be the actual domain. This function will use a global variable if nothing is passed, but feel free to modify it to use the _SERVER variables.
$html is a boolean.
bsp;If true will create links with & else just &
<?php
function create_link($query=NULL, $page=NULL, $secure=NULL, $html=NULL, $port=NULL, $url=NULL ){
if($html === NULL) $html = true;
if($url === NULL){
if($secure==true){
$url = $GLOBALS['_cfg']['secure_site'];
} else {
$url = $GLOBALS['_cfg']['url'];
}
}
if($query === NULL) $query = $_SERVER['QUERY_STRING'];
if($port === NULL && isset($_SERVER['BIBIVU-HTTPD'])){
$port === _SERVER_ADMIN_PORT;
}
if((isset($_SERVER['BIBIVU-HTTPD']) || !isset($_COOKIE[session_name()])) && $this->is_crawler()===false){
$query = $query.($query!=''?'&':'').session_name().'='.session_id();
}
if(substr($query,0,1) == '&'){
$query = $this->change_query(substr($query,1));
}
if($page === NULL) $page = $_SERVER['PHP_SELF'];
$page = str_replace('//','/',$page);
if(substr($page,0,1)=='/') $page = substr($page,1);
$newQry = array();
if($query!=''){
parse_str($query, $newQuery);
foreach($newQuery as $key => $item){
$newQry[] = $key.'='.$item;
}
}
if($html){
//I create the URL in HTML
$query = implode('&', $newQry);
} else {
$query = implode('&', $newQry);
}
if(isset($_.
ost .= $_SERVER['HTTP_HOST'];
}
} else {
if($secure==true){
$host = 'https://'.$url;
} else {
$host = 'http://'.$url;
}
}
if($port==NULL){
//check the current port used
$port = $_SERVER['SERVER_PORT'];
if($port<=0) $port = 80;
}
if($port!=80 && $port!=443){
$host .=':'.$port;
}
if($page===''){
$ret = $query;
} else {
$ret = $host.'/'.$page.($query!=''?'?'.$query:'');
}
return $ret;
}
function change_query($addto_query, $queryOld = NULL){
// change the QUERY_STRING adding or changing the value passed
if ($queryOld === NULL){
$query1 = $_SERVER['QUERY_STRING'];
} else {
$query1 = $queryOld;
}
parse_str ($query1, $array1);
parse_str ($addto_query, $array2);
$newQuery = array_merge($array1, $array2);
foreach($newQuery as $key => $item){
$newQry[] = $key . '=' . $item;
}
return implode('&', $newQry);
}
?>
www.navioo.com
<?php
$data = array('user'=>array('name'=>'Bob Smith',
'age'=>47,
'sex'=>'M',
.
n style="color: #DD0000">'opera', 'poker', 'rap'),
'children'=>array('bobby'=>array('age'=>12,
'sex'<.
style="color: #0000BB">8,
'sex'=>'F')),
'CEO');
echo
http_build_query($data, 'flags_');
?>
php.ru
Correct implementation of coding the array of params without indexes (valdikks fixed code - didnt work for inner arrays):
<code>
function cr_post($a,$b='',$c=0)
{
if (!is_array($a)) return false;
foreach ((array)$a as $k=>$v)
{
if ($c)
{
if( is_numeric($k) )
$k=$b."[]";
else
$k=$b."[$k]";
}
else
{ if (is_int($k))
$k=$b.$k;
}
&nb.
nbsp; }
return implode("&",$r);
}
</code>
php.net
<?php
$data = array('user'=>array('name'=>'Bob Smith',
'age'=>47<.
nbsp; 'dob'=>'5/12/1956'),
'pastimes'=>array('golf', 'opera', 'poker', 'rap'),
'children'=>array('bobby'=>array(