为什么打印' '并打印'\ '在PHP中显示相同的输出?

<?php
print '
';
print '\
';
?>

For the above php code, i got output the following output:(http://ideone.com/vKRtgb)




So, what is the difference between print' ' and print'\ ' ? I know that singly quoted strings are treated literally, but I expected the output to be \ instead of

Because in single-quoted strings in PHP can only escape single quotes and backslashes. Use double-quoted strings for escaping other characters like .

From the PHP documentation linked above:

To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as or , will be output literally as specified rather than having any special meaning.

PHP only interprets escaped characters (with the exception of the escaped backslash \ and the escaped single quote \') when in double quotes (")