Tuesday, March 1, 2011

html parser codeigniter library?

Does someone here know a html parser library that will work with codeigniter?

From stackoverflow
  • Similar questions have been asked here and here

    Hopefully that helps.

    More possibilities include DOMDocument::loadHTML and PHP Simple HTML DOM Parser

    Gerard Banasig : they don't work with codeigniter AFAIK
    Gerard Banasig : Thanks a lot @jacolyte but those are native php libraries, I need one that will run with codeigniter's library system
    Bruce Alderson : Most libraries can be used with CodeIgniter (I frequently use `markdown` and others). Just `require` them from a centra location (like `config/configure.php`), or place them in `libraries/` with a CI-style class wrapper.
    Jessedc : Why do you need one that 'will run with codeigniters library system' ? What difference does it make?
    Gerard Banasig : a php library needs to be extended modified to fit the library structure of codeigniter http://codeigniter.com/user_guide/general/creating_libraries.html
  • I was able to figure out how to run Simple_html_dom php library on codeigniter

    I copied the file Simple_html_dom.php to

    /system/libraries
    

    Then in my controller I call it using

    require_once('Simple_html_dom.php');    
    

    To use it I initialized it using this line

    $html = new Simple_html_dom();
    

    Load a page or link using the line

    $html->load_file('http://www.google.com');
    

    and parse or find elements using this line

    $html->find('table tr td')->plaintext;
    

    works fine and fits right to what I needed to do.

    Matthew : Also, you can probably put it in /application/libraries instead of /system/libraries (I think that's the suggested practice).

0 comments:

Post a Comment