I am trying to compare two strings and remove any characters that appear in second string. For example:
$stringA="abcdefg" ;
$stringB="ayfcghifh" ;
I want $stringB to be "yhih". Are there any ways to do it?
Thanks for the help...
echo ereg_replace("[" . $stringA . "]", "", $stringB);
would be a convenient way to do so.
Or using preg_replace()
$stringB = preg_replace('/[' . preg_quote($stringA, '/') . ']/', '', $stringB);
As an added benefit, you can have case-insensitivity with the /i modifier and Unicode support with /u.
str_replace() as it is more flexible and its performance is in the same order of magnitude.