p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: forms: displaying results when a user enters an apostrophe


Message #1 by "David Sharpington" <gatton@c...> on Tue, 11 Feb 2003 10:18:52
Hello

I have text area in a form. That's passed to the next page OK but, when I 
echo the variable, I get a whole bunch of backslashes eg, if "there's" is 
entered, "there\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s" is displayed.

I can't get the syntax of the echo statement right to overcome this and 
haven't found it in the book yet.

Could someone point me in the right direction, please?

Thanks very much

Dave S
Message #2 by "Nikolai Devereaux" <yomama@u...> on Tue, 11 Feb 2003 13:03:50 -0800
> I have text area in a form. That's passed to the next page OK but, when I
> echo the variable, I get a whole bunch of backslashes eg, if "there's" is
> entered, "there\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s" is displayed.
>
> I can't get the syntax of the echo statement right to overcome this and
> haven't found it in the book yet.
>
> Could someone point me in the right direction, please?


If the user submits text, stripslashes() usually takes care of most character
escaping issues.

I don't have any idea why so many backslashes would appear in the output.


Here's a test script for you:

<?php

echo "<form method=\"get\" action=\"{$_SERVER['PHP_SELF']}\">\n";
echo "  <textarea name=\"text\" rows=\"5\" ></textarea>\n";
echo "  <input type=\"submit\" name=\"Go\" />\n";
echo "</form>\n";

if(isset($_GET['text']))
{
    echo "<pre>\n";
    echo "Without stripslashes: {$_GET['text']}\n";
    echo "With stripslashes:    " . stripslashes($_GET['text']) . "\n";
    echo "</pre>\n";
}

?>



Enjoy!

Nik


  Return to Index