Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

str_replace not working [closed]

Tags:

php

I want to delete all occurrences of this substring from my html file:

<span style="font-size: 12pt;">BLANK PAGE</span>

I tried str_replace, thinking that 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: Mystery solved! Thanks to everyone for letting me know that this should work. Turns out the problem had nothing to do with str_replace! I had grabbed the html string from firebug, not realizing that firebug inserts spaces to "prettify" the html. That's why str_replace failed to find this exact pattern. I would ideally like to delete this question, since the problem ended up having nothing to do with str_replace. Is that possible?

like image 761
moondog Avatar asked Sep 24 '11 06:09

moondog


2 Answers

str_replace() returns the new version - you need to assign it back to the variable (or a new variable):

$myhtml = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $myhtml);
like image 121
Amber Avatar answered Nov 16 '22 02:11

Amber


It should work that way. Did you perhaps forget to assign the result back to your variable?

$myhtml = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $myhtml);
like image 23
Howard Avatar answered Nov 16 '22 00:11

Howard