note 98943 deleted from function.htmlentities by danbrown

From: Date: Fri, 16 Jul 2010 18:51:10 +0000
Subject: note 98943 deleted from function.htmlentities by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170924@lists.php.net to get a copy of this message
Note Submitter: php at shitware dot nl ---- 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; } ?>

« previous php.notes (#170924) next »