Home >Backend Development >PHP Problem >How to delete specified characters in a string in php
How to delete specified characters in a string in php
1. You can replace the specified characters with empty characters by using the "str_replace()" function , to achieve the effect of deleting the specified characters.
$str="abcdefg"; $str=str_replace('a','',$str); echo $str;
2. Use the "substr_replace()" function and the "strpos()" function together to replace the specified characters with empty characters.
$a = "abcababa"; $count=strpos($a,"ab"); $str=substr_replace($a,"",$count,2);
Recommended tutorial: "PHP Tutorial"
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!