Weird issue with fread or file_get_contents
Posted: Wed Dec 09, 2009 7:52 pm
I got some really weird issue with fread or file_get_contents. For example I'm reading javascript file and I'm getting string literals backslashed or escaped.
For example:
gets read as:
What makes things complicated is that it happens in Symfony framework project. It does not happen when I create one simple PHP file to do this operation.
But Symfony's any automatic escaping mechanism cannot or should not cause this behavior, because
How can this issue happen? No escaping mechanism cannot apply on code above according to my knowledge.
And no matter whether I use file_get_contents or fread.
Can anyone help?
For example:
Code: Select all
typeof text == "string"Code: Select all
typeof text == \"string\"But Symfony's any automatic escaping mechanism cannot or should not cause this behavior, because
Code: Select all
// when I read file
$code = file_get_contents($file);
// and for testing, directly after reading, I write out the read content, IT IS ESCAPED
file_put_contents('read_asset_code.txt', date('Y-m-d H:i:s').': '.$file.': '.$code, FILE_APPEND);And no matter whether I use file_get_contents or fread.
Can anyone help?