How to remove symbols from a string by php
Most people do not understand the knowledge points of this article "php how to remove the symbols in the string", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php how to remove the symbols in the string" article.
Methods: 1, remove the specified symbols with "str_replace (" specified symbols ",", $str) "; 2, use" preg_match_all ("/ [\ x {4e00} -\ x {9fa5} a-zA-Z0-9] / u", "$str", $result); filter out all symbols.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php removes symbols from a string
Method 1: use the str_replace () function to remove the specified symbol
The str_replace () function searches for a specified symbol in a string and replaces it with an empty character.
For example: get rid of? Symbol
Method 2: use the preg_match_all () function
The preg_match_all () function can filter strings with regular expressions, leaving only Chinese, English and numbers, and removing all other symbols.
The preg_match_all () function takes a third argument of an array type, which is used to store all matching results.
You can use the join () function to concatenate the resulting array into a string
Echo join ('', $result [0])
The above is about the content of this article on "how to remove symbols from a string in php". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.