Home  >  Article  >  Backend Development  >  How to remove Chinese characters in string in php

How to remove Chinese characters in string in php

王林
王林Original
2020-08-01 14:03:214087browse

php method to delete Chinese characters in a string: You can use the preg_replace() function to replace Chinese characters with empty characters. The preg_replace() function performs a regular expression search and replacement. The search pattern can be a string or an array of strings.

How to remove Chinese characters in string in php

The preg_replace function performs a regular expression search and replace.

(Recommended tutorial: php graphic tutorial)

Syntax:

mixed preg_replace(mixed $pattern, mixed $replacement, mixed $subject[,int $limit = -1[,int &$count]])

Return value:

If subject is an array , preg_replace() returns an array, otherwise a string. If a match is found, the replaced subject is returned, otherwise the unchanged subject is returned. If an error occurs, NULL is returned.

Parameters:

  • #$pattern: The pattern to be searched, which can be a string or a string array.

  • $replacement: String or array of strings used for replacement.

  • $subject: The target string or string array to be searched and replaced.

  • $limit: Optional, the maximum number of substitutions for each subject string per pattern. The default is -1 (no limit).

  • $count: Optional, the number of times the replacement is performed.

(Video tutorial recommendation: php video tutorial)

Code implementation:

";  
    print_r($arr);  
    echo "
"; } $a = "河蟹)(社会afeowa#$%^!@@#zf吃饭fawgwea汉堡包agho_iawghowi我日)"; $result = preg_replace('/([\x80-\xff]*)/i','',$a); p($result);

The above is the detailed content of How to remove Chinese characters in string in php. For more information, please follow other related articles on the PHP Chinese website!

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