note 57544 added to function.htmlspecialchars

From: Date: Thu, 06 Oct 2005 21:40:00 +0000
Subject: note 57544 added to function.htmlspecialchars
Groups: php.notes 
Request: Send a blank email to php-notes+get-96534@lists.php.net to get a copy of this message
I am not sure, maybe I'm missing something, but I have found something interesting: I've been working on a project, where I had to use htmlspecialchars (for opbvious reasons). I olso needed to de-code the encoded string. What I have done was almost a copy and paste from php.net: $trans=get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES); $trans=array_flip($trans); $string=strtr($encoded, $trans); (it looked a bit different in my code, but the idea is clear) I couldn't get the apostrophe sign de-coded, and I needed it for the <A> tags. After an hour or so of debuging, I decided do print_r($trans). What I got was: ... [&#39;] => ' ... BUT the apostrophe was encoded to $#039; -> note the zero. I don't suppose it's a bug, but it definetely IS a potential pitfall, watch out for this one. ---- Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57544 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57544&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57544&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96534) next »