I have an array with a bunch of strings, some of which contain the following code:
<SPAN style="font:7.0pt "Times New Roman""> </SPAN>
When I try to do a
str_replace("<SP开发者_开发问答AN style=\"font:7.0pt "Times New Roman"\"> </SPAN>","",$var);
It does not get caught.
Any ideas why not?
Function str_replace returns the replaced string, so you must do:
$var=str_replace("<SPAN style=\"font:7.0pt "Times New Roman"\"> </SPAN>","",$var);
EDIT: But you should consider using strip_tags() or preg_replace(), for instance like this:
$var=preg_replace('#<span( [^>]+)?>(.*)</span>#iu','\\2',$var)
(replaces all tags and closing tags - I haven't tested, test before using)
I think the formatting in $var for the string you are searching is different. I tried this:
$var = 'dsfdsfdsf<SPAN style="font:7.0pt "Times New Roman""> </SPAN>idshfudsyfuisdfy';
echo str_replace("<SPAN style=\"font:7.0pt "Times New Roman"\"> </SPAN>","",$var);
It outputs dsfdsfdsfidshfudsyfuisdfy
I would suggest you output $var and check if it really is what you expect.
精彩评论