Home > Article > Backend Development > What to do if backslash cannot be used in php
The backslash cannot be used in php because if you want to use the backslash symbol to escape special characters, you need to use a double-quoted string instead of a single-quoted string. The code is like "fwrite($handle, "test\r\ntest");".
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
What should I do if the backslash cannot be used in php ?
To use the backslash notation to escape special characters you need to use a double quoted string instead of a single quoted string, try this:
fwrite($handle, 'test\r\ntest'); // not working fwrite($handle, "test\r\ntest"); // works as expected
Noteworthy The thing is, if your data comes from other sources (non-PHP files, web forms), you may skip the issue entirely, and it will only occur if you hardcode the strings in the script file. For more information, please feel free to browse the relevant man pages:
http://www.php.net/manual/en/language.types.string.php
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if backslash cannot be used in php. For more information, please follow other related articles on the PHP Chinese website!