Home  >  Article  >  Backend Development  >  Segment Chinese and English sentences without garbled characters_PHP tutorial

Segment Chinese and English sentences without garbled characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:38:231180browse

Thinking:
1. Encode the string with urlencode.
2. Use regular expressions to search for sentences ending with transcoded punctuation.
3.urldecode decoded data ​ ​

[Code] [PHP]Code

1 echo urlencode(',-.-?-!-;-,-。-?-!-;-......').PHP_EOL; 2 $str "测试测试,Test test.Test test?Test test!Test test;Test testTest testTest test?测试测试!测试测试;测试测试......"; 3 echo $str; 4         $str = urlencode($str); 5         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); 6         foreach($matchs[0] as $v){ 7             $newArr[] = urldecode($v); 8         } 9         var_dump($newArr);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735092.htmlTechArticleIdeas: 1. Encode the string with urlencode. 2. Use regular expressions to search for sentences ending with transcoded punctuation. 3.urldecode decoded data [Code] [PHP] Code 1 echo urlencode( ,-.-?-!-;-,-....
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