Topic: Prevent conversion of empty tags to self-closing ones
htmLawed does not have an option to prevent conversion of empty tags to self-closing ones (for example, '<br>' to '<br />'). One can consider one of the following methods to retain empty tags without the self-closing ' /' in the htmLawed output:
(1) A string-replace run on htmLawed-filtered output: Perhaps the simplest way. E.g.,
$out = htmLawed($in, ...);
$out = str_replace (" />", ">", $out);
(2) Use the $config 'hook_tag' parameter: When $config parameter 'hook_tag' is set to the name of a custom function, htmLawed allows tag values, after any security/administration-related filtering, to be processed by the custom function. This can be used to prevent conversion of empty tags to self-closing ones. E.g.,
// For htmLawed hook_tag; ensures that empty tags are not self-closed (e.g., '<br>' stays as '<br>')
function my_no_self_closing_function($element, $attribute_array=0){
// If second argument is not received, it means a closing tag is being handled
if(is_numeric($attribute_array)){
return "</$element>";
}
$string = '';
foreach($attribute_array as $k=>$v){
$string .= " {$k}=\"{$v}\"";
}
return "<{$element}{$string}>";
}
// htmLawed processing
$config = array(..., 'hook_tag' => 'my_no_self_closing_function', ...);
$out = htmLawed($in, $config, ...);
(3) Modify htmLawed code: E.g.
// Find in htmLawed.php, at the end of function hl_tag():
return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
// Change to:
return "<{$e}{$aA}>";