我想从我的html文件中删除所有出现的子字符串:
<span style="font-size: 12pt;">BLANK PAGE</span>
Run Code Online (Sandbox Code Playgroud)
我试过str_replace,认为这将是一个简单的解决方案,但它不起作用:
$html = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $html);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
更新:神秘解决了!感谢大家让我知道这应该有用.原来问题与str_replace无关!我从firebug中抓取了html字符串,没有意识到firebug插入空格来"美化"html.这就是str_replace未能找到这种确切模式的原因.理想情况下我想删除这个问题,因为问题最终与str_replace无关.那可能吗?
Amb*_*ber 15
str_replace() 返回新版本 - 您需要将其分配回变量(或新变量):
$myhtml = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $myhtml);
Run Code Online (Sandbox Code Playgroud)
它应该这样工作。您是否忘记将结果分配回您的变量?
$myhtml = str_replace('<span style="font-size: 12pt;">BLANK PAGE</span>', '', $myhtml);
Run Code Online (Sandbox Code Playgroud)