simplehtmldom API
Easy html parsing
Cool things first:
- Have you ever wanted to do some str_replace (or maybe just extract it) only over the plaintext part of a html document?
- Now you can do it with a Drupal module.
- Now you can get/set all kinds of html tags and their attributes or inner text. Easy.
If you like what we do and we made your life better - you can buy us a beer (TODO: beer link to come :) ).
TODO: Upload a segments video screencast with a brief showcase.
simplehtmldom API for Drupal - What this module is and what it does
This is a wrapper around the latest version of the simplehtmldom PHP library - so that Drupal developers can easily write their modules using it from a Drupal API module instead of donwloading it separately for every module and taking care of updating it....
Wrapper means that this module has ONE line only - the require_once() call .
Wrapper means also that the version numbers of this API module will follow the version of the wrapped library. Timely updates will be done.
What the library does is that it gives you the simplest way to parse the html DOM tree - - whenever you need to parse html :
- in your drupal input filters
- in hook_alter();
- when migrating html sites to drupal
Installation and Usage
Download and enable.
Usage example: (use in your module's code)
// Create a DOM object
$html_obj = new simple_html_dom();
// Load HTML from a string
$html_obj->load($node->body);
foreach ($html_obj->find('text') as $plain_text_obj ) {
$plain_text_obj->innertext = ""; // or some str_replace, preg_replace - have fun
}
// now all plain text parts are gone and you are left with the naked html tags - COOL Huh :)?
echo "debug:|>" . $html_obj . "<|";
Here are the docs :
http://simplehtmldom.sourceforge.net/index.htm
http://simplehtmldom.sourceforge.net/manual.htm
http://simplehtmldom.sourceforge.net/manual_api.htm
License
The library is released with a MIT License which according to Wikipedia is compatible with GPL 2.0, thus it can be embeded in drupal modules.
Modules using it:
- Glossify Internal Links Auto SEO
Author:
rsvelko - http://drupal.org/user/337401 from the team of Segments.at - your drupal partner.
