I have a file that has a line of code like this:
$var = "<link rel=\"stylesheet\" href=\"" . GLOBAL_PATH . "system/modules/" . $path . "/" . $css . "\" media=\"screen\">"
I’m opening it into a then saving it back to the server. When I save back to the server using fwrite() and then reopen I get this:
$var = "<link rel="stylesheet" href="" . GLOBAL_PATH . "system/modules/" . $path . "/" . $css . "" media="screen">"
…where the slashes escaping the quotes are gone.
They’re not “gone”, as they were technically not in the original string. Consider this:
… as
$strstring stores only one symbol (a double quote mark), and backslash is used to prevent it from being misread as an ending of the string literal.While PHP is able to magically restore ‘lost’ slashes (with
magic_quotes_runtimedirective), it’s been deprecated in PHP 5.3 and removed in 5.4.The alternative is using addslashes() function when you indeed need them restored.