开发者

urlencode but ignore certain chars

It is possible to run the urlencode function with开发者_Python百科out converting # or % ?


Can you not just do:

$str = urlencode($str);
$str = str_replace("%23", "#", $str);
$str = str_replace("%25", "%", $str);


As far as I know, it's not possible with the urlencode function itself, but you could do a simple string replacement on the encoded results to achieve that:

function my_urlencode($input){
   $input=urlencode($input); 
   return str_replace(array("%25","%23"),array("%","#"),$input);
}


I don't think so, but I guess you could replace the equivalent codes from the encoded string back with # and %.


There are a number of examples in the comments section on the PHP Docs of urlencode for alternative functions. You could simply take the most appropriate function for your needs and remove any replacements for # and %.

http://php.net/manual/en/function.urlencode.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜