Jump to content

apostrophes and urlencode help


dadamssg87

Recommended Posts

i have a textarea in my form. If my validation script detects an error it will send it to the same page with what they had in that textarea encoded in the url. The script detects the $_GET['variable'], decodes it, and stores it as the default in the textarea so they don't have to retype it all again. The problem is the apostrophes add 7 slashes when it gets added back to the textarea. heres the relevant snippets..

 

<?php
function clean_post($variable)
{
$cxn = mysqli_connect($host,$user,$passwd,$dbname) or (mysqli_error($cxn));
   return mysqli_real_escape_string($cxn, strip_tags($variable));
}
$description = clean_post($_POST['description']);
$description = str_replace(array('\r\n', '\r', '\n'), ' ', $description);
$description = urlencode($description);
$base = "http://mywebsite.com/";

        $url = $base."?mm=1&tt=".$description;
$location = "Location:".$url;
die(header($location));

 

and then to output it in the textarea

<?php
$tt = urldecode(strip_tags($_GET['tt']));
<textarea id=location name=location maxlength="140" >
<?php echo $tt; ?>
</textarea>

 

and this is what my url ends up looking like

http://mysite.com/wordpress/?mm=3&tt=what\\\%27s+the+deal%3F

 

and this ends up in my textarea

"what\\\\\\\'s the deal?"

Link to comment
https://forums.phpfreaks.com/topic/233173-apostrophes-and-urlencode-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.