Str_replace not working
I want to remove all occurrences of this substring from my html file:
<span style="font-size: 12pt;">BLANK PAGE</span> I tried str_replace, believing that this would be a simple solution, but it does not work:
$html = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $html); Any suggestions?
UPDATE: The mystery is solved! Thanks to everyone who informed me that this should work. Turns out the problem has nothing to do with str_replace! I grabbed the html string from firebug, not realizing that firebug inserts spaces to preflot html. Therefore str_replace could not find this exact template. Ideally, I would like to remove this question, since the problem had nothing to do with str_replace. Is it possible?
str_replace() returns the new version - you need to assign it back to a variable (or a new variable):
$myhtml = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $myhtml); It should work this way. Did you forget to assign the result to your variable?
$myhtml = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $myhtml); My problem was that I used str_replace to replace special characters like (á, é, í, ó, ú) and that didn't work. I tried using notepad ++ by modifying the file that utf8 enters without specification, uploaded the file to the server and it will work!
you cannot replace html tags using str_replace. It replaces only accurate events. If you want to replace the range text with strip_tags to remove all tags and change the range text with str_replace.