note 90111 modified in function.htmlentities by thiago
| From: | thiago@php.net | Date: | Tue, 07 Apr 2009 12:33:12 +0000 |
| Subject: | note 90111 modified in function.htmlentities by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152892@lists.php.net to get a copy of this message | ||
I took one of the previous functions above - (which only encodes the string once - which is great)
and added the ability to encode & -> &
See below.
Its a shame we cant do this straight with htmlentities (with double encode set to false)
<?php
function htmlButTags($str) {
// Take all the html entities
$caracteres = get_html_translation_table(HTML_ENTITIES);
// Find out the "tags" entities
$remover = get_html_translation_table(HTML_SPECIALCHARS);
// Spit out the tags entities from the original table
$caracteres = array_diff($caracteres, $remover);
// Translate the string....
$str = strtr($str, $caracteres);
// And that's it!
// oo now amps
$str =
preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" ,
$str);
return $str;
}
?>
--was--
I took one of the previous functions above - (which only encodes the string once - which is great)
and added the ability to encode & -> &
See below.
Its a shame we cant do this straight with htmlentities (with double encode set to false)
function htmlButTags($str) {
// Take all the html entities
$caracteres = get_html_translation_table(HTML_ENTITIES);
// Find out the "tags" entities
$remover = get_html_translation_table(HTML_SPECIALCHARS);
// Spit out the tags entities from the original table
$caracteres = array_diff($caracteres, $remover);
// Translate the string....
$str = strtr($str, $caracteres);
// And that's it!
// oo now amps
$str =
preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" ,
$str);
return $str;
}
http://php.net/manual/en/function.htmlentities.php