2011-01-10 57 views
5

アップデート1:完全なソースコードで:PHPQueryでHTMLタグを削除するには?

$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でこれを行うことは可能ですか?あなたがこれを行うのと同じように見えるのドキュメントから

よろしく、

答えて

10

この作品:

$html->find('script')->remove(); 
echo $html; 

これは動作しません:

$html = $html->find('script')->remove(); 
echo $html; 
6

$doc->remove('script'); 

http://code.google.com/p/phpquery/wiki/Manipulation#Removing

EDIT:この作品はPHPQueryにバグがありますように

が見えます代わりに:

$doc->find('script')->remove(); 
+0

こんにちは、返信に感謝を。それは動作していません。それ以上の手がかりは?よろしくお願いします。 –

+0

テストする人のために、より多くの情報を提供する必要があります。あなたはHTMLを供給できますか? –

+0

私はコードを更新しました。すべての手がかりは?よろしくお願いします。 –

1

私はこのような単純なものがうまくいくことを望んでいた。 pq( 'td [colspan = "2"]') - > remove( 'b'); 残念ながら、私が望んでいたように、それはうまくいきませんでした。 私はこのstackoverflowに遭遇し、成功しなかったことを何度も試しました。

これは私のために働いたものです。

$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 want 
関連する問題