例如,如何编写一个PHP函数来转换
http://abc.com/hi-1?source=google转换为
3http % % 2 f % 2 abc.com % 2 fhi-1 % 3 fsource % 3 dgoogle
注:一些异常不应该被转换,比如'。' '——'
谢谢。
http://php.net/manual/en/function.urlencode.php
或
http://www.php.net/manual/en/function.rawurlencode.php
<?php
$string = "http://abc.com/hi-1?source=google";
echo urlencode($string); //echo rawurlencode($string);
http://php.net/manual/en/function.rawurlencode.php
echo rawurlencode("http://abc.com/hi-1?source=google");