Search code examples
phpfwrite

strip slashes in php linux


I want to ask a very simple question.

I am working on a project in which I have entered a code, say I am entering a code like :

<?php
echo "Test";
?>

On click of a save button, This code is being saved into a php file say testfile.php.

When I am running this file on windows 7 - wamp server, then this is OK, but When I hosted this file on 000webhost.com which is linux server then some backslashes (\) are added before " ". For writing into file, I am using code

$code = $_POST['yourcode'];
$openphp = fopen("testfile.php","w");
fwrite($openphp, $code);
fclose($openphp);

In Linux server, this code is written as :

<?php
echo \"test\";

?>

I dont want to save this backslashes (\), how can I avoid this while writing the file


Solution

  • Create an .htaccess file in the same folder as your script and add the following

    php_flag magic_quotes_gpc Off