ressio / pharse

Fastest PHP HTML Parser
83 stars 15 forks source link

Fatal error with deleteChild() #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Thank you for this code! It is great!

Working with it, I found a little issue:

When I want to get an element without children:

                $p = str_get_dom($html); 

        $b = $p('*',0);

        //Iterate over childnodes
        for ($i = 1; $i < $b->childCount(); $i++) {
          $b->deleteChild($i);
        }

I get this:

Notice: Undefined offset: 0 in 
/Applications/XAMPP/xamppfiles/htdocs/lubith/v2/version/2.0.0/library/html/ganon
/ganon.php on line 1302

Fatal error: Call to a member function delete() on a non-object in 
/Applications/XAMPP/xamppfiles/htdocs/lubith/v2/version/2.0.0/library/html/ganon
/ganon.php on line 1302

I've change line 1302 from

    $this->children[$child]->delete();

        to

    if(isset($this->children[$child])) $this->children[$child]->delete();

Now it is working.

Original issue reported on code.google.com by ktork...@gmail.com on 26 Mar 2013 at 3:03

GoogleCodeExporter commented 9 years ago
Thanks for your report, but this error is probably because you are trying to 
delete a child that does not exist.
When you start with index 1 with your deletion, the number of nodes will 
shrink, and the nodes will change order. When a child is deleted, all the 
following children move up one index. This way, when you want to remove the 
last child, it is actually at index 1. Try reversing your loop :)

Original comment by niels....@gmail.com on 7 Apr 2013 at 4:02

GoogleCodeExporter commented 9 years ago
Thank you very much. I realised it after I posted the issue and I didn't find 
an option to edit or delete it. 

Thank you again for this great code. It is the best of its kind, I've tested 
some others but in one way or another they are inferior to Ganon.

I've searched and read on the forums. Some other libraries are more popular and 
people don't talk very often about Ganon. My first impression was that Ganon 
has a lot of missing features. This is because you have to download it and take 
a look to the included documentation in order to understand what is capable of.

My suggestion would be to add a list of function with a short description (like 
in doc.). This way a visitor may quickly understand that it has all the 
features needed by a HTML parser.

Original comment by ktork...@gmail.com on 10 Apr 2013 at 9:50