php method to remove a certain string: first use the strpos() function to find the first occurrence of the specified string in another string; then use the substr_replace() function to remove the found string That’s it.
strpos() function finds the first occurrence of a string within another string (case sensitive).
(Recommended tutorial: php graphic tutorial)
Syntax:
strpos(string,find,start)
Parameters:
string Required. Specifies the string to be searched for.
#find Required. Specifies the characters to search for.
#start Optional. Specifies the location from which to start the search.
substr_replace() function replaces part of a string with another string and returns the replaced string. If string is an array, the array is returned.
(Video tutorial recommendation: php video tutorial)
Grammar:
substr_replace(string,replacement,start,length)
Simple code implementation:
$a = "abcababa"; $count=strpos($a,"ab"); $str=substr_replace($a,"",$count,2);
The above is the detailed content of How to remove a certain string in php. For more information, please follow other related articles on the PHP Chinese website!