It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
已关闭8年。
我需要反斜杠才能成为字符串的一部分。我该怎么做?
当转义下一个字符将导致解析错误(字符串的引号终止)或有效的转义序列(在双引号的字符串中)时,则需要转义反斜杠:
已关闭8年。
我需要反斜杠才能成为字符串的一部分。我该怎么做?
最佳答案
当反斜杠\
不能转义字符串的终止引号或以其他方式创建有效的转义序列(用双引号引起来的字符串)时,以下两种方法中的任一个都会产生一个反斜杠:
$string = 'abc\def';
$string = "abc\def";
//
$string = 'abc\\def';
$string = "abc\\def";
当转义下一个字符将导致解析错误(字符串的引号终止)或有效的转义序列(在双引号的字符串中)时,则需要转义反斜杠:
$string = 'abcdef\\';
$string = "abcdef\\";
$string = 'abc\012';
$string = "abc\\012";
关于php - 您如何在PHP中使用反斜杠制作字符串? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4764729/