note 98027 added to function.htmlentities
| From: | Seb at osu1 dot php dot net | Date: | Fri, 21 May 2010 12:38:00 +0000 |
| Subject: | note 98027 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169488@lists.php.net to get a copy of this message | ||
I have recently built the function which converts all special characters from a given string, but
excapes all html tags and if there are already any valid special characters - it simply ignores
them.
Here it is:
function encodeHTML($string) {
$pattern = '<([a-zA-Z0-9\.\, "\'_\/\-\+~=;:\(\)?&#%![\]@]+)>';
// put text only, devided by html tags into array
$textMatches = preg_split('/' . $pattern . '/', $string);
// array for sanitised output
$textSanitised = array();
foreach($textMatches as $key => $value) {
$textSanitised[$key] = htmlentities(html_entity_decode($value, ENT_QUOTES, 'UTF-8'),
ENT_QUOTES, 'UTF-8');
}
foreach($textMatches as $key => $value) {
$string = str_replace($value, $textSanitised[$key], $string);
}
return $string;
}
----
Server IP: 69.147.83.197
Probable Submitter: 93.97.189.29
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- https://master.php.net/note/edit/98027
Del: integrated -- https://master.php.net/note/delete/98027/integrated
Del: useless -- https://master.php.net/note/delete/98027/useless
Del: bad code -- https://master.php.net/note/delete/98027/bad+code
Del: spam -- https://master.php.net/note/delete/98027/spam
Del: non-english -- https://master.php.net/note/delete/98027/non-english
Del: in docs -- https://master.php.net/note/delete/98027/in+docs
Del: other reasons-- https://master.php.net/note/delete/98027
Reject -- https://master.php.net/note/reject/98027
Search -- https://master.php.net/manage/user-notes.php