note 118874 added to function.htmlspecialchars
| From: | DavidSpector | Date: | Sat, 20 Feb 2016 15:52:36 +0000 |
| Subject: | note 118874 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204996@lists.php.net to get a copy of this message | ||
At least two years ago an important PHP application I wrote (an order processing system) stopped
working in certain cases, with text being erased, requiring difficult manual intervention. As
described in other comments here, the problem was that code like
"$Str=htmlspecialchars($Str)" had stopped working reliably. I've found that
Dave's solution presented here did not work for me in every case.
I finally solved this problem by replacing all such htmlspecialchars calls with the following
function, which should work for every character encoding:
function SafeStr($Str) // For showing user input on page in HTML
{
return
str_replace(array('&','<','>','"','\''),
array('&','<','>','"','''),
$Str);
} // SafeStr
----
Server IP: 72.52.91.14
Probable Submitter: 67.253.38.31
----
Manual Page -- http://php.net/manual/en/function.htmlspecialchars.php
Edit -- https://master.php.net/note/edit/118874
Del: integrated -- https://master.php.net/note/delete/118874/integrated
Del: useless -- https://master.php.net/note/delete/118874/useless
Del: bad code -- https://master.php.net/note/delete/118874/bad+code
Del: spam -- https://master.php.net/note/delete/118874/spam
Del: non-english -- https://master.php.net/note/delete/118874/non-english
Del: in docs -- https://master.php.net/note/delete/118874/in+docs
Del: other reasons-- https://master.php.net/note/delete/118874
Reject -- https://master.php.net/note/reject/118874
Search -- https://master.php.net/manage/user-notes.php