View Full Version : Function for Description field validation

07-03-2007, 05:10 PM
Ok so i was wondering if anyone had a good function that takes the POST of a text area and then add's the slashes into it, makes http://, www., etc into links as well as <a href> into links and also whenever someone hits return in the textarea to create that into a <br />

I have this code here, but it doesn't allow me to use <a href> and also when i select the value from the database stripslashes doesn't remove the slashes from the description field. Anyone have ideas?

function validateDescription($theinput, $description = '') {
if(trim($theinput != "")) {
$result = (get_magic_quotes_gpc) ? addslashes($theinput) : stripslashes($theinput);
$result = preg_replace("/(http|https|ftp)\:\/\/([a-zA-Z\d\.\-\_\?\#\&\=]+)/i",'<a href="$1://$2">$1://$2</a>', $result);
$result = nl2br($result);
return true;
} else {
$this->errors[] = $description;
return false;

07-03-2007, 06:36 PM
If you properly insert data from a textarea into a database then the slashes will not be stored. Use mysql_real_escape_string() to escape the text and prevent the backslashes from getting into the stored value.