function search_by_page_strip_tags in Search by Page 8
Same name and namespace in other branches
- 6 search_by_page.module \search_by_page_strip_tags()
- 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_search_by_page_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.
5 calls to search_by_page_strip_tags()
- hook_search_by_page_details in ./
search_by_page.api.php - Return details about an indexed path (required sub-module hook).
- SearchByPageUnitTest::testStripTags in tests/
src/ Unit/ SearchByPageUnitTest.php - Tests the search_by_page_strip_tags function.
- search_by_page_nodes_search_by_page_details in search_by_page_nodes/
search_by_page_nodes.module - Implements Search by Page hook_search_by_page_details().
- search_by_page_paths_search_by_page_details in search_by_page_paths/
search_by_page_paths.module - Implements Search by Page hook_search_by_page_details().
- search_by_page_update_index in ./
search_by_page.module - Implements hook_update_index().
File
- ./
search_by_page.module, line 208 - 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;
}