php urlencode with charset

<? php
function parseurl($url="",$input_charset,$output_charset)  
{
//1  
$url = rawurlencode(mb_convert_encoding($url, $input_charset, $output_charset));  
$entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
$replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
//2
$url = str_replace($entities, $replacements, $url);  
return $url;  
} 
>


没有搜到一个通用、完备的解法,只好自己copy修改了个
第一步,编码转换
第二步,反转义

参考资料:http://tuzwu.iteye.com/blog/648214

你可能感兴趣的:(PHP,Blog)