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

PHP中英文断句无乱码

PHP中文网
Release: 2016-05-25 17:08:26
Original
1643 people have browsed it

思路:  
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);
Copy after login

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


Related labels:
php
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template