note 107221 added to function.htmlentities
| From: | Anonymous at osu1 dot php dot net | Date: | Tue, 17 Jan 2012 19:16:20 +0000 |
| Subject: | note 107221 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185680@lists.php.net to get a copy of this message | ||
Unfortunately, this function will mangle foreign characters, for instance,
ããããæã
ã¯åº often gets turned into stuff like
îáóâÃ. If you want to retain that data, then use the
mb_encode_numericentity function, which will encode string ranges to unicode. Below is an
implementation that encodes only special chars, so that "a" won't be converted to its
unicode equivalent.
<?php
// Author: holdoffhunger@gmail.com
// License: AGPL3
// Input:
// Hello! <=> ããããæã
ã¯åº!
$format_array = array(
// Handle Chars 0x00 to 0x1f = White Spacing and Technical Chars
0x0000, 0x001f, 0, 0xffff,
// Handle Char 0x3c = Lesser-Than Sign
0x003c, 0x003c, 0, 0xffff,
// Handle Char 0x3e = Greater-Than Sign
0x003e, 0x003e, 0, 0xffff,
// Handle Chars 0x007f to 0xffff = All Other Chars
0x007f, 0xffff, 0, 0xffff
);
$formatted_user_input = mb_encode_numericentity($formatted_user_input, $format_array,
'UTF-8');
// Output:
// Hello! <=>
そもそも我々は出!
?>
----
Server IP: 69.147.83.197
Probable Submitter: 68.9.137.178
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- https://master.php.net/note/edit/107221
Del: integrated -- https://master.php.net/note/delete/107221/integrated
Del: useless -- https://master.php.net/note/delete/107221/useless
Del: bad code -- https://master.php.net/note/delete/107221/bad+code
Del: spam -- https://master.php.net/note/delete/107221/spam
Del: non-english -- https://master.php.net/note/delete/107221/non-english
Del: in docs -- https://master.php.net/note/delete/107221/in+docs
Del: other reasons-- https://master.php.net/note/delete/107221
Reject -- https://master.php.net/note/reject/107221
Search -- https://master.php.net/manage/user-notes.php