开发者

Is there a reason why PHP does not catch this substring?

开发者 https://www.devze.com 2023-03-29 00:05 出处:网络
I have an array with a bunch of strings, some of which contain the following code: <SPAN style=\"font:7.0pt &quot;Times New Roman&quot;\"> </SPAN>

I have an array with a bunch of strings, some of which contain the following code:

<SPAN style="font:7.0pt &quot;Times New Roman&quot;"> </SPAN>

When I try to do a

str_replace("<SP开发者_开发问答AN style=\"font:7.0pt &quot;Times New Roman&quot;\"> </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 &quot;Times New Roman&quot;\"> </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 &quot;Times New Roman&quot;"> </SPAN>idshfudsyfuisdfy';

echo str_replace("<SPAN style=\"font:7.0pt &quot;Times New Roman&quot;\"> </SPAN>","",$var);

It outputs dsfdsfdsfidshfudsyfuisdfy

I would suggest you output $var and check if it really is what you expect.

0

精彩评论

暂无评论...
验证码 换一张
取 消