Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

What this module is and what it does

This is a bridge between the latest version of the PHP Simple HTML DOM Parser (simplehtmldom) library - so that Drupal developers can easily write their modules using its API.

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

Easy html parsing

  • 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.

Installation and Usage

For 7.x-2.x and 6.x-2.x please download simplehtmldom library (README.txt)
Download and enable the module.

Usage example for Drupal 7: (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[LANGUAGE_NONE][0]['value']);

  // Remove all plain text fragments.
  foreach ($html_obj->find('text') as $plain_text_obj ) {
    $plain_text_obj->innertext = "";
  }

  // Display the results.
  echo $html_obj;
          
  // Release resources to avoid memory leak in some versions.
  $html_obj->clear(); 
  unset($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 embedded in Drupal modules. However, the library is not included in the module package starting with 2.x version.

Modules using it:

Authors and maintainers:

Author: rsvelko from the team of Segments.at - your drupal partner.
Co-maintainer: Konstantin Komelin

Versions 6.x-2.x and 7.x-2.x:

These versions don't contain simplehtmldom library inside, now it's external dependency. It allows us to use whichever version of simplehtmldom library we like. Please follow instructions in the README.txt to install the module properly.

Support of these versions was initially sponsored by Explorable.com

If you're using Theme developer please note that it's currently incompatible with simplehtmldom 7.x-2.x. Use 7.x-1.12 instead.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Aug 2024
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
8.x-2.0-alpha1 Pre-release Aug 8, 2024