如何正确的用PHP进行url编码

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

echo myUrlEncode('http://192.168.8.232/红尘情歌 高安.mp4');
//输出 http://192.168.8.232/%E7%BA%A2%E5%B0%98%E6%83%85%E6%AD%8C%20%E9%AB%98%E5%AE%89.mp4

本文为创建文章,网址 http://blog.p2hp.com/archives/5501

如何正确的用PHP进行url编码urlencode
标签: