note 104022 added to function.html-entity-decode
| From: | Ramil at osu1 dot php dot net | Date: | Wed, 18 May 2011 04:38:43 +0000 |
| Subject: | note 104022 added to function.html-entity-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179839@lists.php.net to get a copy of this message | ||
Thanx Daniel its very useful.
I use this function
function utf8et ($string) {
$string = preg_replace("/[\302-\375]([\001-\177])/", "�\\1",
$string);
$string = preg_replace("/[\340-\375].([\001-\177])/", "�\\1",
$string);
$string = preg_replace("/[\360-\375]..([\001-\177])/", "�\\1",
$string);
$string = preg_replace("/[\370-\375]...([\001-\177])/", "�\\1",
$string);
$string = preg_replace("/[\374-\375]....([\001-\177])/", "�\\1",
$string);
$string = preg_replace("/[\300-\301]./", "�", $string);
$string = preg_replace("/\364[\220-\277]../", "�", $string);
$string = preg_replace("/[\365-\367].../", "�", $string);
$string = preg_replace("/[\370-\373]..../", "�", $string);
$string = preg_replace("/[\374-\375]...../", "�", $string);
$string = preg_replace("/[\376-\377]/", "�", $string);
$string = preg_replace("/[\302-\364]{2,}/", "�", $string);
$string = preg_replace(
"/([\360-\364])([\200-\277])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')&7)<<18 |
(ord('\\2')&63)<<12 |" .
" (ord('\\3')&63)<<6 |
(ord('\\4')&63)).';'",
$string);
$string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')&15)<<12 |
(ord('\\2')&63)<<6 | (ord('\\3')&63)).';'",
$string);
$string = preg_replace("/([\300-\337])([\200-\277])/e",
"'&#'.((ord('\\1')&31)<<6 |
(ord('\\2')&63)).';'",
$string);
$string = preg_replace("/[\200-\277]/", "�", $string);
return $string;
}
function utf8decode ($text)
{
$text= html_entity_decode($text,ENT_QUOTES,"UTF-8");
$text= preg_replace('/&#(\d+);/me',"chr(\\1)",$text);
$text= preg_replace('/&#x([a-f0-9]+);/mei',"chr(0x\\1)",$text);
return $text;
}
----
Server IP: 69.147.83.197
Probable Submitter: 85.132.15.154
----
Manual Page -- http://www.php.net/manual/en/function.html-entity-decode.php
Edit -- https://master.php.net/note/edit/104022
Del: integrated -- https://master.php.net/note/delete/104022/integrated
Del: useless -- https://master.php.net/note/delete/104022/useless
Del: bad code -- https://master.php.net/note/delete/104022/bad+code
Del: spam -- https://master.php.net/note/delete/104022/spam
Del: non-english -- https://master.php.net/note/delete/104022/non-english
Del: in docs -- https://master.php.net/note/delete/104022/in+docs
Del: other reasons-- https://master.php.net/note/delete/104022
Reject -- https://master.php.net/note/reject/104022
Search -- https://master.php.net/manage/user-notes.php