| 7 filter.module | _filter_url_escape_comments($match, $escape = NULL) |
| 8 filter.module | _filter_url_escape_comments($match, $escape = NULL) |
preg_replace callback to escape contents of HTML comments
Parameters
$match: An array containing matches to replace from preg_replace_callback(), whereas $match[1] is expected to contain the content to be filtered.
$escape: (optional) Boolean whether to escape (TRUE) or unescape comments (FALSE). Defaults to neither. If TRUE, statically cached $comments are reset.
Related topics
1 call to _filter_url_escape_comments()
1 string reference to '_filter_url_escape_comments'
File
- modules/
filter/ filter.module, line 1540 - Framework for handling filtering of content.
Code
function _filter_url_escape_comments($match, $escape = NULL) {
static $mode, $comments = array();
if (isset($escape)) {
$mode = $escape;
if ($escape) {
$comments = array();
}
return;
}
// Replace all HTML coments with a '<!-- [hash] -->' placeholder.
if ($mode) {
$content = $match[1];
$hash = md5($content);
$comments[$hash] = $content;
return "<!-- $hash -->";
}
// Or replace placeholders with actual comment contents.
else {
$hash = $match[1];
$hash = trim($hash);
$content = $comments[$hash];
return "<!--$content-->";
}
}
Login or register to post comments