note 83856 deleted from function.urlencode by peehaa
| From: | peehaa@php.net | Date: | Fri, 06 Jan 2017 15:51:16 +0000 |
| Subject: | note 83856 deleted from function.urlencode by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208696@lists.php.net to get a copy of this message | ||
Note Submitter: php dot net at unixen dot dk
----
>> Hi muthuishere , i saw your excellent contribution, but couldnt make it work, so i
>> corrected some bits and pieces and had the following done:
<?php
function SmartUrlEncode($url){
if (strpos($url, '=') === false):
return $url;
else:
$startpos = strpos($url, "?");
$tmpurl=substr($url, 0 , $startpos+1) ;
$qryStr=substr($url, $startpos+1 ) ;
$qryvalues=explode("&", $qryStr);
foreach($qryvalues as $value):
$buffer=explode("=", $value);
$buffer[1]=urlencode($buffer[1]);
endforeach;
$finalqrystr=implode("&", &$qryvalues);
$finalURL=$tmpurl . $finalqrystr;
return $finalURL;
endif;
}
?>
As you see its very much yours, modfied primarily using '&' instead of
'&', and ofcourse an if test to see if anything in input is to be cursed... Thanks for
great function !