in PHP string, how to convert non-alphanumeric characters to ascii in hex
For example, how to write a PHP function to convert
http://abc.com/hi-1?source=google
to be converted into
http%3A%2F%2abc.com%2Fhi-1%3Fsource%3Dgoogle
P.S. some exception should be开发者_Go百科 not be converted, like '.' '-'
Thanks.
http://php.net/manual/en/function.urlencode.php
or
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");
精彩评论