Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function for Description field validation

    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?

    PHP Code:
    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;
            }
        } 

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •