php拼接html标签 双引号,如何处理这个HTML代码作为单引号和双引号引用PHP?

有很多方法可以逃避内容:

$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就足够了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值