Home >Backend Development >PHP Problem >How to delete specified characters in a string in php?
The str_replace() function can be used in php to delete the specified characters in the string; the str_replace() function can replace the specified characters in the string. When the replaced value is a null character, the specified characters can be deleted. Character, the syntax is "str_replace('specified character','', string)".
Recommendation: "PHP Video Tutorial"
str_replace() function replaces some characters in the string (differentiate case) and returns a string or array with the replacement value.
Syntax:
str_replace(find,replace,string,count)
Parameters:
find Required. Specifies the value to look for.
replace Required. Specifies the value to replace the value in find.
string Required. Specifies the string to be searched for.
count Optional. A variable counting the number of substitutions.
str_replace() 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.
php deletes the specified characters in the string
The str_replace() function can replace the specified characters in the string. When the replacement value is When the empty character ('') is entered, the specified character can be deleted
Example: Use the str_replace() function to replace the h character of the string with empty, thereby deleting the specified character in the string.
Output result:
For more programming-related knowledge, please visit:Introduction to Programming ! !
The above is the detailed content of How to delete specified characters in a string in php?. For more information, please follow other related articles on the PHP Chinese website!