note 49689 added to function.addslashes
| From: | sundevil at hexagonomistico dot com | Date: | Fri, 04 Feb 2005 21:12:15 +0000 |
| Subject: | note 49689 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84543@lists.php.net to get a copy of this message | ||
Hey! if you will use a database to store data that will only be accessible through a web page i.e.
just for web purposes, you may use other kind of filters. I recommend to use first the addcslashes()
function, in order to escape line feeds and then to replace those line feeds by the corresponding
html tag. And finally use the htmlentities() function in order to replace those annoying quotes or
other characters by their corresponding html tag.
For example, data stored in a textarea as:
"hola"
<hola>
más niños
May be filtered using: addcslashes($textarea, "\n,\\"), as:
"Hola"\n<hola>\nmás niños
Then, using: htmlentities($textarea,ENT_QUOTES), should return:
"Hola"\n<hola>\nmás niños
(Which has just converted the special characters in their html tags)
Finally, using: str_replace('\n','<br>',$textarea), may add a html line
feed everytime it encounters a \n. So, when you retrieve data from the database you will be able to
use it as html code just as typed!
(perhaps retrieving into a textarea gives a little more problem! Oops!)
----
Manual Page -- http://www.php.net/manual/en/function.addslashes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49689
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49689&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49689&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49689&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49689&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49689&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49689&report=yes
Search -- http://master.php.net/manage/user-notes.php