note 54669 added to function.htmlspecialchars
| From: | jspalletta at gmail dot com | Date: | Tue, 12 Jul 2005 12:37:24 +0000 |
| Subject: | note 54669 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91798@lists.php.net to get a copy of this message | ||
I have found that this regular expression is sufficient for making sure that existing character
entities show after htmlspecialchars() replaces _all_ occurrences of & with the &
entity.
<?php
// Note: hsc is an abbreviation of htmlspecialchars
function hscFixed($str)
{
return preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;",
htmlspecialchars($str));
}
?>
The only flaw I can think of is if you have text of the vein; "&[word];", that is not
meant to be a character but rather uses the ampersand and semicolon in their traditional grammatical
denotations. However I think this is highly unlikely to occur (among other reasons, the fact that
anyone with enough grammatical inclination to use them as such probably won't leave out the
space between the ampersand and the word).
----
Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54669
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54669&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54669&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54669&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54669&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54669&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54669&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54669&report=yes
Search -- http://master.php.net/manage/user-notes.php