2011-01-10 4 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

편집 :이 작품은 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 
관련 문제