Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an HTML tag with PHPQuery?

Tags:

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,

like image 340
André Avatar asked Jan 10 '11 16:01

André


1 Answers

This works:

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

This doesn't work:

$html = $html->find('script')->remove();
echo $html;
like image 53
Mat Weir Avatar answered Sep 25 '22 01:09

Mat Weir