Home  >  Article  >  Backend Development  >  Segment Chinese and English sentences without garbled characters - PHP

Segment Chinese and English sentences without garbled characters - PHP

WBOY
WBOYOriginal
2016-07-25 08:50:041212browse
Ideas:
1. Encode the string with urlencode.
2. Use regular expressions to search for sentences ending with transcoded punctuation.
3.urldecode decode data
  1. echo urlencode(',-.-?-!-;-,-.-?-!-;-...').PHP_EOL;
  2. $str = "Code snippet, code snippet. Code snippet? Code snippet! Code snippet; Code snippet. Code snippet! Code snippet; Code snippet...";
  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);
Copy code


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