note 83693 added to function.urlencode

From: Date: Sun, 08 Jun 2008 04:50:22 +0000
Subject: note 83693 added to function.urlencode
Groups: php.notes 
Request: Send a blank email to php-notes+get-140219@lists.php.net to get a copy of this message
Most of us may need a function if they have entire URL but you need to be encoding only the query values , not the URL and not the parameters The below function takes an URL as input and applies url encoding only to the parameter values /****************************************** For eg www.google.com/?q=alka rani&start=100 urlencode ==> www.google.com/search?q=alka+rani&start=100 if you change it to rawurlencode ==> www.google.com/search?q=alka%20rani&start=100 **************************************/ function SmartUrlEncode($url){ //Extract the Querystr pos after ? mark $startpos = stripos($url, "?"); //Extract the URl alone $tmpurl=substr($url, 0 , $startpos+1) ; //echo $tmpurl . "<br>"; //Extract the Querystr alone $qryStr=substr($url, $startpos+1 ) ; //echo $qryStr . "<br>"; //Split the querystring into & pairs $qryvalues=explode("&", $qryStr); foreach($qryvalues as &$value) { //Split the single data into two i.e data | value $buffer=explode("=", $value); // Urlencode only the value now , Change it to rawurlencode if necessary $buffer[1]=urlencode($buffer[1]); //Join values back in the array $value = implode("=", $tmp); } //Output Querystr ,Join all the pairs with & $finalqrystr=implode("&", $qryvalues); // echo $finalqrystr . "<br>"; $finalURL=$tmpurl . $finalqrystr; //echo $finalURL . "<br>"; return finalURL; } } ---- Server IP: 209.41.74.194 Probable Submitter: 66.26.56.179 ---- Manual Page -- http://www.php.net/manual/en/function.urlencode.php Edit -- https://master.php.net/note/edit/83693 Del: integrated -- https://master.php.net/note/delete/83693/integrated Del: useless -- https://master.php.net/note/delete/83693/useless Del: bad code -- https://master.php.net/note/delete/83693/bad+code Del: spam -- https://master.php.net/note/delete/83693/spam Del: non-english -- https://master.php.net/note/delete/83693/non-english Del: in docs -- https://master.php.net/note/delete/83693/in+docs Del: other reasons-- https://master.php.net/note/delete/83693 Reject -- https://master.php.net/note/reject/83693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140219) next »