有很多方法可以逃避内容:
$a = 5;
$b = array(3);
// Single quotes treats the insides as you type it, except for a few like
// double-backslash (which makes a backslash) or backslash apostrophe, which
// allows a single apostrophe, so including a dollar sign inside will actually
// print it out to screen
$content = 'This will print a literal dollar sign followed by an "a": $a'; // $a
$content = 'This will print a backslash and a literal dollar sign followed by an "a": \$a'; // \$a
// However, variables inside double quotes get resolved with their variable values,
// unless you have preceded the dollar sign with a backslash to let it be treated
// as a literal dollar
$content = "This will include the value of variable \$a, as it is looking for a variable: $a"; // 5
$content = "This will print a literal dollar sign followed by an \"a\" because we have backslash-escaped it: \$a"; // $a
// For cases where you need to use brackets with your variable and you wish to transclude
// the content, you need to enclose the variable inside curly braces. This helps PHP know
// that the variable has actually ended, and that you didn't want to actually print the
// bracket afterward
$content = 'This will print a literal dollar sign followed by an "a" and enclosed in braces: {$a}'; // {$a}
$content = "This will include the value of variable \$a, as it is looking for a variable: {$a}"; // 5
$content = 'This will print a literal dollar sign followed by an "a" and brackets and enclosed in braces: {$b[0]}'; // {$b[0]}
$content = "This will include the value of variable \$a, as it is looking for a variable: {$b[0]}"; // 3...在HTML(或XML,包括真正的XHTML)中,您也可以进行转义;无论HTML中是单引号还是双引号,都可以使用转义:
对引号内使用的引号有帮助:
撇号内的撇号有帮助:
请注意,十六进制往往更有用,因为它也在JavaScript中使用:
var content = '\u0027'; // '和CSS
p:before {content: '\27'} /* ' */在JavaScript中,双引号或单引号具有相同的含义(除了事实,您需要反斜杠 - 转义不同的字符)。
在CSS中它是相同的,但反斜杠是不同的,因为它们通常预期后面是十六进制Unicode序列(或另一个反斜杠),否则将被忽略。
在JavaScript中(与PHP中的双引号一样),反斜杠在转义其他序列(例如'\ n'或其他反斜杠)时可能具有特殊含义,但是否则会被忽略。
您可以找到这些用于查找任何字符的“Unicode代码点”,不仅用于标点符号,还用于任何脚本中的任何字符。这些通常表示为U + 00A0或U + 0027(注意它也可以包括字母A-F)。很少,他们可以要求6位数(或2位四位数的组合),但通常4就足够了。