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

Segment Chinese and English sentences without garbled characters_PHP tutorial

WBOY
Release: 2016-07-13 10:38:23
Original
1212 people have browsed it

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( ,-.-?-!-;-,-....
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template