note 98943 added to function.htmlentities
| From: | php at shitware dot nl | Date: | Fri, 16 Jul 2010 18:48:34 +0000 |
| Subject: | note 98943 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170923@lists.php.net to get a copy of this message | ||
Little shorter version of silverbeat -eat- gmx -hot- at function (although it lacks $encodeTags, but
that should be easy):
<?php
function utf8_entities($str){
$result = '';
$len = strlen($str);
for($i = 0; $i < $len; $i++){
$ord = ord($char = $str[$i]);
if($ord < 0x80) $result .= $char; //ascii
elseif($ord >= 0xc0){ //multi-byte
$n = 2 + (int)($ord >= 0xe0) + (int)($ord >= 0xf0); //byte-count
$code = ($ord & (0x7f >> $n)); //1st byte
while(--$n) $code = ($code << 6) + (ord($str[++$i]) & 0x3f);
$result .= "&#$code;";
}
}
return $result;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 213.197.254.243
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- https://master.php.net/note/edit/98943
Del: integrated -- https://master.php.net/note/delete/98943/integrated
Del: useless -- https://master.php.net/note/delete/98943/useless
Del: bad code -- https://master.php.net/note/delete/98943/bad+code
Del: spam -- https://master.php.net/note/delete/98943/spam
Del: non-english -- https://master.php.net/note/delete/98943/non-english
Del: in docs -- https://master.php.net/note/delete/98943/in+docs
Del: other reasons-- https://master.php.net/note/delete/98943
Reject -- https://master.php.net/note/reject/98943
Search -- https://master.php.net/manage/user-notes.php