note 49332 deleted from function.htmlentities by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 11:25:14 +0000 |
| Subject: | note 49332 deleted from function.htmlentities by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189588@lists.php.net to get a copy of this message | ||
Note Submitter: marques at displague dot com
----
htmlEncodeText (below) needs a small tweak, the dash needs to be made literal to get picked up in
cases like '<a href="blah-blah.php">'. I have been using this function to
parse my postgresql database calls since I have alot of unicode data and I don't want HTML data
to be neutered (via htmlentities()).
<?php
function htmlEncodeText ($string)
{
$pattern = '<([a-zA-Z0-9\.\, "\'_\/\-\+~=;:\(\)?&#%![\]@]+)>';
preg_match_all ('/' . $pattern . '/', $string, $tagMatches, PREG_SET_ORDER);
$textMatches = preg_split ('/' . $pattern . '/', $string);
foreach ($textMatches as $key => $value) {
$textMatches [$key] = htmlentities ($value);
}
for ($i = 0; $i < count ($textMatches); $i ++) {
$textMatches [$i] = $textMatches [$i] . $tagMatches [$i] [0];
}
return implode ($textMatches);
}
?>
--Editor note: Combined some corrections to the regex pattern, thanks to fabian dot lange at web dot
de, hammertscrew at veryweb dot com, webmaster AT scholesmafia DOT co DOT uk, thomas AT cosifan DOT
de and marques at displague dot com---