如何使用 PHPQuery 删除 HTML 标签?
更新1:带有完整的源代码:
$html1 = '<div class="pubanunciomrec" style="background:#FFFFFF;"><script type="text/javascript"><!--
google_ad_slot = "9853257829";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';
$doc = phpQuery::newDocument($html1);
$html1 = $doc->remove('script');
echo $html1;
源代码是上面的。我还了解到存在一个错误,http://code.google。 com/p/phpquery/issues/detail?id=150 不知道是否解决了。
有关如何删除脚本的任何线索来自这个 HTML?
谨致问候,
您好,
我需要删除所有<脚本>使用 PhpQuery 从 HTML 文档中提取标签。
我已完成以下操作:
$doc = phpQuery::newDocument($html);
$html = $doc['script']->remove();
echo $html;
它没有删除<脚本>;标签和内容。用 PhpQuery 可以做到这一点吗?
此致,
Update1: With the full source code:
$html1 = '<div class="pubanunciomrec" style="background:#FFFFFF;"><script type="text/javascript"><!--
google_ad_slot = "9853257829";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';
$doc = phpQuery::newDocument($html1);
$html1 = $doc->remove('script');
echo $html1;
The source code is this the above. I have also read that exists a bug, http://code.google.com/p/phpquery/issues/detail?id=150 I don't know if it is solved.
Any clues on how to remove the <script> from this HTML?
Best Regards,
Hi,
I need to remove all <script> tags from a HTML document using PhpQuery.
I have done the following:
$doc = phpQuery::newDocument($html);
$html = $doc['script']->remove();
echo $html;
It is not removing the <script> tags and contents. It is possible to do this with PhpQuery?
Best Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有效:
这不起作用:
This works:
This doesn't work:
从文档来看,您似乎会这样做:
http://code.google。 com/p/phpquery/wiki/Manipulation#Removing
编辑:
看起来 PHPQuery 中有一个错误,这有效:
From the documentation it looks like you would do this:
http://code.google.com/p/phpquery/wiki/Manipulation#Removing
EDIT:
Looks like there's a bug in PHPQuery, this works instead:
我希望像这样简单的事情会起作用
pq('td[colspan="2"]')->删除('b');
不幸的是它没有像我希望的那样工作。
我遇到了这个 stackoverflow 并尝试了提到的内容但没有成功。
这对我有用。
I was hoping something simple like this would work
pq('td[colspan="2"]')->remove('b');
Unfortunately it did not work as I hoped.
I ran across this stackoverflow and tried what was mentioned without success.
This is what worked for me.