Wednesday, October 17, 2012

PHP Function to Create URLs


$url = 'http://maheshbokkisam.blogspot.com/create_url.php';

$data = array("a"=>1, "b"=>3, "c"=>'');

_make_url($url, $data);


/** 

 * Create url with url and uri 

 * @param url and uri data (array)

 * return string (url) 

*/

function _make_url($url='http://'.$_SERVER['SERVER_NAME'], $data){

$data = array_diff($data, array(''=>'')); 

              // remove empty keys from uri data array

               return (count($data) > 0) ? $url.'?'.http_build_query($data, 'flags_') : $url;

}