note 98027 added to function.htmlentities

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.