note 46717 added to function.htmlspecialchars

From: Date: Thu, 21 Oct 2004 08:03:53 +0000
Subject: note 46717 added to function.htmlspecialchars
Groups: php.notes 
Request: Send a blank email to php-notes+get-78869@lists.php.net to get a copy of this message
Quite often, on HTML pages that are not encoded as UTF-8, and people write in not native encoding, some browser (for sure IExplorer) will send the different charset characters using HTML Entities, such as &#1073; for small russian 'b'. htmlspecialchars() will convert this character to the entity, since it changes all & to &amp; What I usually do, is either turn &amp; back to & so the correct characters will appear in the output, or I use some regex to replace all entities of characters back to their original entity: <?php // treat this as pseudo-code, it hasn't been tested... $result = preg_replace('/&amp;#(x[a-f0-9]+|[0-9]+);/i', '&#$1;', $source); ?> ---- Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46717 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46717&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46717&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46717&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46717&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46717&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46717&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46717&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78869) next »