Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

simplehtmldom API

Security covered Under active development 3,788 sites

This project provides a bridge to the Simple HTML DOM Parser library, allowing Drupal developers to easily parse and manipulate HTML content within their modules. It offers a simple way to extract, modify, or remove specific HTML elements and their attributes or text.

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.

Ask your assistant about simplehtmldom API

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

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 PHP Release date
8.x-2.0-alpha1 Pre-release 8–10 Aug 8, 2024