DOMParser - CSS3 Selectors in PHP

Because PHP just doesn't do HTML.
Because XML parsers stop working when you don't close a tag that doesn't need to be closed.
And because you want something light, easy and quick. Something that JUST WORKS.

(We know that the standards police would prefer you use the PECL DOM library.
But you know you have a deadline to make...)

Simple:

The library has only two methods:
  • get() returns the elements you need.
  • set() allows you to modify one or many elements, and returns the modified HTML.

Flexible:

It doesn't care how poorly you wrote the XML.
If you're happy, it's happy. :)

Light:

Speed and low-memory footprint are built into every step of this library.
I mean, this baby crossed the finish at Daytona 500 before the Kellogs car had hit the gas!

So, how do I use it?

  1. Call the class [args: your content(HTML or a URL), options]
  2. Call get [args: CSS selectors, options], or set [args: CSS selectors, new content, options]
  3. Rinse, Lather, repeat
  4. Here's an example, but see the demo page for more.
    $dom = new DOMParser('www.google.com');
    
    //echos <input value="" title="Google Search" class="lst" size="55" name="q" maxlength="2048" autocomplete="off"/>	
    echo get('input[title$=search]');
    
    //echos Google's homepage without the search bar.
    echo set('input[title$=search], '<div>Sorry, the internet is closed</div>');
    
    //Hey, that's Google you're messing with! Changes the title :)
    echo set('input[title$=search], array('title' => 'Yahoo Search') );