PHP searches for the code for specifying a string in a string and deletes it. Searching the Internet says this, but the actual effect is not that good, or in other words, the effect is not good at all
<code><span><span><?php </span><span>$a</span> = <span>"abcababa"</span>; <span>$count</span>=strpos(<span>$a</span>,<span>"ab"</span>); <span>$str</span>=substr_replace(<span>$a</span>,<span>""</span>,<span>$count</span>,<span>2</span>); var_dump(<span>$str</span>); <span>?></span></span></span></code>
The effect is as follows,
OK, this may be the effect you want, but the function that comes with PHP can perfectly solve this problem
The code is as follows
<code><span><span><?php </span> var_dump(str_replace(<span>"ab"</span>,<span>""</span>,<span>"abcaasdfads"</span>)); <span>?></span></span></span></code>
The official explanation is as follows
Grammar:
str_replace(find,replace,string,count)
Parameter Description
find: required. Specifies the value to be found.
replace: required. Specifies the value to replace the value in find.
string: required. Specifies the string to be searched for.
count: optional. Variable counting the number of substitutions.
In fact, each has its own strengths. The first one is a small algorithm that can limit the number of characters to be replaced, while the second one is to replace all characters. It is a personal choice based on the actual situation.
The above introduces the code for PHP to find a specified string in a string and delete it, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.