I've written a simple function to convert an UTF-8 string to URL encoded string. All the given characters are converted!
The function:
<?php
function mb_rawurlencode($url){
$encoded='';
$length=mb_strlen($url);
for($i=0;$i<$length;$i++){
$encoded.='%'.wordwrap(bin2hex(mb_substr($url,$i,1)),2,'%',true);
}
return $encoded;
}
?>
Example:
<?php
echo 'http://example.com/',
mb_rawurlencode('你好');
?>
The above example will output:
http://example.com/%e4%bd%a0%e5%a5%bd