note 106929 added to function.htmlentities

From: Date: Mon, 19 Dec 2011 10:20:47 +0000
Subject: note 106929 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-185137@lists.php.net to get a copy of this message
Hi there, after several and several tests, I figured out that dot: - htmlentities() function remove characters like "à","è",etc when you specify a flag and a charset - htmlentities() function DOES NOT remove characters like those above when you DO NOT specify anything So, let's assume that.. <?php $str = "Hèèèllooo"; $res_1 = htmlentities($str, ENT_QUOTES, "UTF-8"); $res_2 = htmlentities($str); echo var_dump($res_1); // Result: string '' (length=0) echo var_dump($res_2); // string 'H&egrave;&egrave;&egrave;llooo' (length=30) ?> I used this for a textarea content for comments. Anyway, note that using the "$res_2" form the function will leave unconverted single/double quotes. At this point you should use str_replace() function to perform the characters but be careful because.. <?php $str = "'Hèèèllooo'"; $res_2 = str_replace("'","&#039;",$str); $res_2 = htmlentities($str); echo var_dump($res_2); // string '&amp;#039;H&egrave;&egrave;&egrave;llooo&amp;#039;' $res_3 = htmlentities($str); $res_3 = str_replace("'","&#039;",$res_3); echo var_dump($res_3); // string '&#039;H&egrave;&egrave;&egrave;llooo&#039;' --> Nice ?> Hope it will helps you. Regards, W.D. ---- Server IP: 69.147.83.197 Probable Submitter: 130.25.33.133 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/106929 Del: integrated -- https://master.php.net/note/delete/106929/integrated Del: useless -- https://master.php.net/note/delete/106929/useless Del: bad code -- https://master.php.net/note/delete/106929/bad+code Del: spam -- https://master.php.net/note/delete/106929/spam Del: non-english -- https://master.php.net/note/delete/106929/non-english Del: in docs -- https://master.php.net/note/delete/106929/in+docs Del: other reasons-- https://master.php.net/note/delete/106929 Reject -- https://master.php.net/note/reject/106929 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185137) next »