note 49689 deleted from function.addslashes by philip
| From: | philip@php.net | Date: | Fri, 31 Mar 2006 15:26:23 +0000 |
| Subject: | note 49689 deleted from function.addslashes by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107079@lists.php.net to get a copy of this message | ||
Note Submitter: sundevil at hexagonomistico dot com
----
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!)