Update1:具有完整的源代码:
$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;源代码就是上面提到的。我也读过一个bug,http://code.google.com/p/phpquery/issues/detail?id=150我不知道它是否解决了。
关于如何从这个HTML中删除,有什么线索吗?</div><div>诚挚的问候,</div><div></div><div>嗨,</div><div>我需要使用<script>从PhpQuery文档中删除所有的PhpQuery标记。</div><div>我做了以下工作:</div><pre><code>$doc = phpQuery::newDocument($html); $html = $doc['script']->remove(); echo $html;</code></pre><div>它不是删除<script>标记和内容。用PhpQuery可以做到这一点吗?</div><div>诚挚的问候,</div><div></div>
发布于 2012-06-06 07:36:58
这样做是可行的:
$html->find('script')->remove();
echo $html;这不管用:
$html = $html->find('script')->remove();
echo $html;发布于 2011-01-10 16:59:14
从文档来看,您可能会这样做:
$doc->remove('script');http://code.google.com/p/phpquery/wiki/Manipulation#Removing
编辑:
看起来在PHPQuery中有一个bug,但是这是可行的:
$doc->find('script')->remove();发布于 2011-09-25 10:16:03
我希望像这样简单的东西能工作pq(‘tdcolspan=“2’)->remove(‘b’);不幸的是它没有像我希望的那样工作。我遇到了这种堆叠溢出,并尝试了提到的,但没有成功。
,这就是对我有用的东西,
$doc = phpQuery::newDocumentHTML($html);
// used newDocumentHTML and stored it's return into $doc
$doc['td[colspan="2"] b']->remove();
// Used the $doc var to call remove() on the elements I did not want from the DOM
// In this instance I wanted to remove all bold text from the td with a colspan of 2
$d = pq('td[colspan="2"]');
// Created my selection from the current DOM which has the elements removed earlier
echo pq($d)->text();
// Rewrap $d into PHPquery and call what ever function you wanthttps://stackoverflow.com/questions/4648819
复制相似问题