note 73708 added to function.htmlentities
| From: | dot) | Date: | Wed, 07 Mar 2007 12:41:47 +0000 |
| Subject: | note 73708 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124193@lists.php.net to get a copy of this message | ||
I've seen lots of functions to convert all the entities, but I needed to do a fulltext search
in a db field that had named entities instead of numeric entities (edited by tinymce), so I searched
the tinymce source and found a string with the value->entity mapping. So, i wrote the following
function to encode the user's query with named entities.
The string I used is different of the original, because i didn't want to convert ' or
". The string is too long, so I had to cut it. To get the original check TinyMCE source and
search for nbsp or other entity ;)
<?php
$entities_unmatched = explode(',', '160,nbsp,161,iexcl,162,cent, [...] ');
$even = 1;
foreach($entities_unmatched as $c) {
if($even) {
$ord = $c;
} else {
$entities_table[$ord] = $c;
}
$even = 1 - $even;
}
function encode_named_entities($str) {
global $entities_table;
$encoded_str = '';
for($i = 0; $i < strlen($str); $i++) {
$ent = @$entities_table[ord($str{$i})];
if($ent) {
$encoded_str .= "&$ent;";
} else {
$encoded_str .= $str{$i};
}
}
return $encoded_str;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 88.157.224.99
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- https://master.php.net/note/edit/73708
Del: integrated -- https://master.php.net/note/delete/73708/integrated
Del: useless -- https://master.php.net/note/delete/73708/useless
Del: bad code -- https://master.php.net/note/delete/73708/bad+code
Del: spam -- https://master.php.net/note/delete/73708/spam
Del: non-english -- https://master.php.net/note/delete/73708/non-english
Del: in docs -- https://master.php.net/note/delete/73708/in+docs
Del: other reasons-- https://master.php.net/note/delete/73708
Reject -- https://master.php.net/note/reject/73708
Search -- https://master.php.net/manage/user-notes.php