In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how php removes non-Chinese letters". In daily operation, I believe many people have doubts about how php removes non-Chinese letters. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how php removes non-Chinese letters". Next, please follow the editor to study!
Php's method to remove non-Chinese letters: use the preg_replace () function with regular expressions to search for non-Chinese letters in a string and replace them with empty characters. The syntax "preg_replace (" / [^\ x {4E00} -\ x {9FFF}] + / u ",', $str)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use the preg_replace () function with regular expressions to remove non-Chinese letters from a string.
The regular expression is: / [^\ x {4E00} -\ x {9FFF}] + / u
Preg_replace () deletion principle: use regular expressions to search for non-Chinese letters in a string and replace them with empty characters''.
Implementation example:
Description: preg_replace ():
The preg_replace () function, which can perform the search and replacement of regular expressions, is a powerful string substitution handler with the following syntax format:
Preg_replace ($pattern, $replacement, $subject [, $limit =-1 [, & $count]])
The parameters are described as follows:
$pattern: the pattern to search for, you can make a string or an array of strings
Replacement: the string or array of strings used for replacement. If this parameter is a string and $pattern is an array, then all patterns are replaced with this string. If both $pattern and $replacement are arrays, each $pattern is replaced with the corresponding element in $replacement. If there are fewer elements in $replacement than in $pattern, the extra $pattern is replaced with an empty string.
$subject: the string or array of strings to search for and replace, if $subject is an array, search and replace back on each element of $subject, and the return value will also be an array.
$limit: optional parameter, the maximum number of times each mode can be replaced on each $subject. The default is-1 (infinite).
$count: optional parameter, if specified, will be populated with the number of completed replacements.
If $subject is an array, the preg_replace () function returns an array and in other cases a string.
If the function preg_replace () searches for a match, it returns the replaced $subject, otherwise it returns the unchanged $subject. Each argument to the preg_replace () function (except the argument $limit) can be an array. If the parameter $pattern and the parameter $replacement are both arrays, the function will process them in the order in which their key names appear in the array. If an error occurs, NULL is returned.
The parameter $replacement can contain backward references\ n or $n, which is syntactically preferred. Each such reference is replaced by the text captured by the nth capture subgroup to which it is matched. N can be 0-99, and\ 0 and $0 represent the complete pattern matching text.
The sequence number of the capture subgroup is counted as follows: the left parenthesis representing the capture subgroup is counted from left to right, starting with 1. If you want to use a backslash in $replacement, you must use four ("\" because this is a string of php first, two after escape, and then considered a literal backslash after passing through the regular expression engine).
When working in replacement mode and the backward reference needs to be followed by another number (for example, adding an original number immediately after a matching pattern), the syntax\ 1 cannot be used to describe the backward reference. For example,\ 11 will make it impossible for preg_replace () to understand whether you want a\ 1 backward reference followed by an original text 1 or a\ 11 backward reference followed by nothing. The solution in this case is to use ${1} 1. This creates a separate $1 backward reference, a separate original text 1.
When the deprecated e modifier is used, this function escapes some characters (that is,', ",\, and NULL) and then performs backward reference substitution. When this is done, make sure that there are no syntax errors caused by single or double quotes (for example: 'strlen (\' $1\') + strlen ('$2)') after backward quote parsing. Make sure that it conforms to PHP's string syntax and conforms to eval syntax. Because after the replacement is completed, the engine evaluates the resulting string as php code using eval and returns the value as the string that ultimately participates in the replacement.
At this point, the study on "how to remove non-Chinese letters from php" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.