dadamssg87 Posted April 9, 2011 Share Posted April 9, 2011 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?" Quote Link to comment https://forums.phpfreaks.com/topic/233173-apostrophes-and-urlencode-help/ Share on other sites More sharing options...
dadamssg87 Posted April 9, 2011 Author Share Posted April 9, 2011 figured it out with magic quotes it's ugly but it fixed it :/ <?php <textarea id=description name=description maxlength="140" > <?php if(get_magic_quotes_gpc()){ echo stripslashes(stripslashes(stripslashes($tt))); } ?> </textarea> Quote Link to comment https://forums.phpfreaks.com/topic/233173-apostrophes-and-urlencode-help/#findComment-1199128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.