keirosang / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

remove on pq element not work #150

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I think there is a bug in the remove() function when called in a pq element.

try :
$content =
file_get_contents('http://www.google.fr/search?hl=fr&q=phpquery+remove');
$content = phpQuery::newDocumentHTML($content);
$logo = pq('#logo', $content);
echo (string) $logo->remove('img');
echo "\n---\n";
echo (string) $logo;
echo "\n---\n";
pq('img', $logo)->remove();
echo (string) $logo;

result :
<a id="logo" href="http://www.google.fr/webhp?hl=fr" title="Afficher la
page d'accueil de Google">Google<img width="167" height="222"
src="/images/srpr/nav_logo13.png" alt=""></a>

---
<a id="logo" href="http://www.google.fr/webhp?hl=fr" title="Afficher la
page d'accueil de Google">Google<img width="167" height="222"
src="/images/srpr/nav_logo13.png" alt=""></a>

---
<a id="logo" href="http://www.google.fr/webhp?hl=fr" title="Afficher la
page d'accueil de Google">Google</a>

expected result :
<a id="logo" href="http://www.google.fr/webhp?hl=fr" title="Afficher la
page d'accueil de Google">Google</a>

---
<a id="logo" href="http://www.google.fr/webhp?hl=fr" title="Afficher la
page d'accueil de Google">Google</a>

---
<a id="logo" href="http://www.google.fr/webhp?hl=fr" title="Afficher la
page d'accueil de Google">Google</a>

Original issue reported on code.google.com by xxorax on 27 May 2010 at 4:09

GoogleCodeExporter commented 8 years ago
Confirmed this occurs with my code also. The workaround is this syntax:

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

Original comment by ryan.doherty on 11 Jan 2011 at 5:40