反斜杠 - 这意味着什么

What is difference between \ and \\?

 echo $path_1="C:\wamp\www\practice\";

Output shows error:

Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN

 echo $path_1="C:\\wamp\\www\\practice\\";

Output:

C:\wamp\www\practice\

Instead of printing C:\\wamp\\www\\practice\\ it prints C:\wamp\www\practice\

Typically in programming the character \ used between normal double quotes " is an escape character for special characters, making it a special character. So to display the \ you have to escape it with another \.

I would also mention that the reason you received a Parse Error is because the ending \ you used in your first example escapes the double quote so the end of line could not be parsed.

Try putting string in single quotes (')

echo $path_1='C:\wamp\www\practice\ '; //notice the space in the end

String inside " is checked for escape sequences and php variables. But string in ' is echoed as it is. So escape all \ when using inside " or write your string in '.

Important note string in ' cannot end with a \. This would escape out the closing quote.