Re: htmlentities() with utf8

From: Date: Mon, 08 May 2006 21:52:03 +0000
Subject: Re: htmlentities() with utf8
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-235764@lists.php.net to get a copy of this message
On 5/4/06, Marten Lehmann <lehmann@cnm.de> wrote:
Hello, I want to use htmlentities() with UTF-8, which I can set with the third parameter. But to use the third parameter, I have to provide the second parameter. Currently the default for the second parameter is ENT_COMPAT. But as this might change, I don't want to call htmlentities with htmlentities($text, ENT_COMPAT, "UTF-8"); all the time. Is there another way? Regards Marten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You could create a function that could handle various output/escaping
functions. This way you minimize any changes to the output mechanism you use throughout your old site. function formatText($text=NULL) { if (is_null($text) )
       return $text;
$text = htmlentities($text, ENT_COMPAT, "UTF-8"); // you could even do other stuff if you wanted like $text = nl2br($text); return $text; }

« previous php.general (#235764) next »