Basically, I have an online text editor, and when you use PHP, before and after every ' or "you get a \. The way the process works is that you type in code into a textare, and when you submit it, it creates a .php file. The code used to genrate the file: <?php $filetype = $_POST['typeoffile']; $user = $_POST['username']; $filename = "".$user."".$filetype.""; $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = $filename; $result = $_POST['code'];$filehandle = fopen($filename, 'w') or die("We have failed to open your file"); fwrite ($filehandle, $result); chmod("$filename", 0777); $onlyconsonants = str_replace($slashes, "", "$host$uri/$extra"); echo "Your file has been succesfully created. Click <a href='http://$host$uri/$extra'>here to view it.<br />" ?> PHP: My input into the textarea: <?php $ret = "hello"; echo $ret; ?> PHP: The contents of the file after generation: <?php $ret = \"hello\"; echo $ret; ?> PHP: How do I fix this, do I have an extra slasdh or something in PHP? Thanks, BP
Easy Just add: $ret = (stripslashes($ret) before: echo $ret; The added slash is there to prevent mysql entries to contain an apostrophe for hackers to ad sql injection. If this is php only and no db interaction you can just do what I posted.
David's suggestion is correct. Here is your code modified: <?php $filetype = $_POST['typeoffile']; $user = $_POST['username']; $filename = "".$user."".$filetype.""; $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = $filename; $result = stripslashes($_POST['code']); $filehandle = fopen($filename, 'w') or die("We have failed to open your file"); fwrite ($filehandle, $result); chmod("$filename", 0777); $onlyconsonants = str_replace($slashes, "", "$host$uri/$extra"); echo "Your file has been succesfully created. Click <a href='http://$host$uri/$extra'>here to view it.<br />" ?> Code (php):
Hello, EdIt :: Your problem is already solve. Please ignore this post Modify your code to following in order to get the required results. <?php $ret = 'hello, is it n\'t your "expected" solution?..'; echo stripslashes($ret); ?> PHP: Hope this will solve your issue, Regards,