In PHP, you can use the str_replace() function to remove a certain character in a string. str_replace() is used to replace some characters in a string in a case-sensitive manner. The syntax format "str_replace('To remove characters','',string)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php remove a certain character from the string
In PHP, you can use the str_replace() function to remove a certain character in a string.
Example: Remove the a character from the string
<?php header('content-type:text/html;charset=utf-8'); $str="abcdefg"; echo "原字符串:",$str,"<br>"; $str=str_replace('a','',$str); echo "去掉a字符的字符串:",$str; ?>
Output:
原字符串:abcdefg 去掉a字符的字符串:bcdefg
Related function description:
str_replace() Function replaces some characters in a string (case sensitive).
This function must follow the following rules:
If the searched string is an array, then it will return an array.
If the searched string is an array, then it will find and replace each element in the array.
If an array needs to be searched and replaced at the same time, and the elements to be replaced are less than the number of found elements, the excess elements will be replaced with empty strings .
If you search an array and replace only one string, the replacement string will work for all found values.
Grammar
str_replace(find,replace,string,count)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove a certain character from a php string. For more information, please follow other related articles on the PHP Chinese website!