I want to search for a particular string/pattern and remove it. The pattern starts off with:
<!DOCTYPE
...and ends with:
]>
I want to remove it, and anything else in-between. Also it should not be case sensitive.
I have tried the str_replace()
function but it does not remove the in between content.
Thanks for the help.
That's a use case for preg_replace. Regular expressions are our friends:
$txt = preg_replace("#<!DOCTYPE(.*?)\]>#sim", "", $txt);
The (.*?)
here matches the shortest possible string within. And ""
is the replacement.
But are you sure that ]>
is the correct string to look for as terminator?