note 111666 added to function.htmlspecialchars
| From: | MikeRobinson | Date: | Thu, 14 Mar 2013 00:46:51 +0000 |
| Subject: | note 111666 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194066@lists.php.net to get a copy of this message | ||
Unfortunately, as far as I can tell, the PHP devs did not provide ANY way to set the default
encoding used by htmlspecialchars() or htmlentities(), even though they changed the default encoding
in PHP 5.4 (*golf clap for PHP devs*). To save someone the time of trying it, this does not work:
<?php
ini_set('default_charset', $charset); // doesn't work.
?>
Unfortunately, the only way to not have to explicitly provide the second and third parameter every
single time this function is called (which gets extremely tedious) is to write your own function as
a wrapper:
<?php
define('CHARSET', 'ISO-8859-1');
define('REPLACE_FLAGS', ENT_COMPAT | ENT_XHTML);
function html($string) {
return htmlspecialchars($string, REPLACE_FLAGS, CHARSET);
}
echo html("ñ"); // works
?>
You can do the same for htmlentities()
----
Server IP: 69.147.83.199
Probable Submitter: 186.176.74.100
----
Manual Page -- http://php.net/manual/en/function.htmlspecialchars.php
Edit -- https://master.php.net/note/edit/111666
Del: integrated -- https://master.php.net/note/delete/111666/integrated
Del: useless -- https://master.php.net/note/delete/111666/useless
Del: bad code -- https://master.php.net/note/delete/111666/bad+code
Del: spam -- https://master.php.net/note/delete/111666/spam
Del: non-english -- https://master.php.net/note/delete/111666/non-english
Del: in docs -- https://master.php.net/note/delete/111666/in+docs
Del: other reasons-- https://master.php.net/note/delete/111666
Reject -- https://master.php.net/note/reject/111666
Search -- https://master.php.net/manage/user-notes.php