Home >php教程 >php手册 >中英文断句无乱码

中英文断句无乱码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:31:401702browse

思路: 1.将字符串用urlencode编码。 2.用正则搜索以转码后的标点结尾的语句。 3.urldecode解码数据 无 源码与演示: 源码出处演示出处 echo urlencode(',-.-?-!-;-,-。-?-!-;-......').PHP_EOL;$str = "代码片段,代码片段.代码片段?代码片段!代码片段;代

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

源码与演示:源码出处 演示出处

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);
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