Home >php教程 >PHP源码 >PHP中英文断句无乱码

PHP中英文断句无乱码

PHP中文网
PHP中文网Original
2016-05-25 17:08:261641browse

思路:  
1.将字符串用urlencode编码。  
2.用正则搜索以转码后的标点结尾的语句。  

3.urldecode解码数据
http://blog.ddian.cn/?post=833

1. PHP代码    

echo urlencode(',-.-?-!-;-,-。-?-!-;-......').PHP_EOL;
$str  = "开源中国,开源中国.开源中国?开源中国!开源中国;开源中国,开源中国。开源中国?开源中国!开源中国;
开源中国......";
echo $str;
        $str = urlencode($str);
        preg_match_all ('/(.*?)(\.{3,6}|%2C|\.|%3F|%21|%3B|%EF%BC%8C|%E3%80%82|%EF%BC%9F|%EF%BC%81|%EF%BC%9B)/',
        $str,$matchs);
        foreach($matchs[0] as $v){
            $newArr[] = urldecode($v);
        }
        var_dump($newArr);

 以上就是PHP中英文断句无乱码的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn