Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    11
    Member #
    24384
    Hi,
    I have a problem with the form on my website

    The problem is that all ' (single-quote), " (double quote) and \ (backslash) are escaped with a backslash automatically.

    I turned off magic_quotes in php.ini, but the problem is still there (I used phpinfo to check that magic_quotes are really off).

    So I used stripslashes() in the code that pass the values into the database:

    Code:
    $articleDetails['comments'] = stripslashes($_POST['comments']);
    $articleDetails['articlenames'] = stripslashes($_POST['articlename']);
    $articleDetails['articlekeywords'] = stripslashes($_POST['articlekeyword']);
    The problem is that it works only for the "General Guidelines for All Articles" textarea ('comments') and not for the 2 other fields: "Subject" + "Keywords/Comments" ('articlenames' + 'articlekeywords')

    Thanks,
    Steve

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    I do this and it works OK:

    $textarea=$_POST['textarea'];
    $newtext=stripslashes($textarea);
    $newtext = str_replace("<?", "", $newtext);
    $newtext = str_replace("?>", "", $newtext);
    $newtext = nl2br($newtext);

    I use stripslashes, then remove any strings that resemble PHP, and then convert my newlines to <br> so it looks right when viewing with HTML. I don't get any escaped characters.

    I wonder if using the $articleDetails array is causing something?
    Maybe test it out similar to what I'm doing. You call your textarea 'comments'. I just named mine 'textarea'.

    NOTE:
    PHP has a function for nl2br (new line to <br>), but there is no reverse function, so here is one to use.

    // convert all of the <br> back into new lines for the textarea display.
    $text=br2nl($text);

    function br2nl($str) {
    return preg_replace('=<br */?>=i', "", $str);
    }



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:45 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com