You are here

function search_by_page_strip_tags in Search by Page 6

Same name and namespace in other branches
  1. 8 search_by_page.module \search_by_page_strip_tags()
  2. 7 search_by_page.module \search_by_page_strip_tags()

Strips out contents of HTML tags that are excluded in the given environment.

Modules should always call this function in their hook_sbp_details() implementation. Note that it differs from the PHP strip_tags in that it strips the text contained within the tags, as well as the tags.

Parameters

$text: Text to be processed.

$envid: Environment ID to use to find list of tags to exclude.

Return value

$text with the specified tags (and their contents) from search_by_page_setting_get('exclude_tags', $envid, '') stripped out.

6 calls to search_by_page_strip_tags()
hook_sbp_details in ./search_by_page.api.php
Return details about an indexed path (required sub-module hook).
sbp_nodes_sbp_details in ./sbp_nodes.module
Implementation of Search by Page hook_sbp_details().
sbp_paths_sbp_details in ./sbp_paths.module
Implementation of Search by Page hook_sbp_details().
sbp_users_sbp_details in ./sbp_users.module
Implementation of Search by Page hook_sbp_details().
SearchByPageUnitTest::testStripTags in tests/search_by_page.test
Tests the search_by_page_strip_tags function.

... See full list

File

./search_by_page.module, line 1733
Main module file for Drupal module Search by Page.

Code

function search_by_page_strip_tags($text, $envid) {
  $tags = search_by_page_setting_get('exclude_tags', $envid, '');

  // Make sure $tags is clean.
  $tags = preg_replace('/[^a-z0-9_ ]/', ' ', strtolower($tags));
  $tags = explode(' ', $tags);

  // Strip tags and their contents, noting that tags could have attributes.
  foreach ($tags as $tag) {
    $tag = trim($tag);
    if ($tag) {
      $text = preg_replace('|<' . $tag . '[^>]*>.*</' . $tag . '>|isUu', '', $text);
    }
  }
  return $text;
}