note 49332 added to function.htmlentities
| From: | marques at displague dot com | Date: | Mon, 24 Jan 2005 18:01:32 +0000 |
| Subject: | note 49332 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83882@lists.php.net to get a copy of this message | ||
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);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49332
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49332&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49332&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49332&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49332&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49332&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49332&report=yes
Search -- http://master.php.net/manage/user-notes.php