【发布时间】:2016-03-18 20:16:16
【问题描述】:
我正在编写一个 HTML 字符串,它需要接收我的一些 PHP 变量。但是,我似乎无法正确转义双引号。
尝试 1:
$html .= '<span class="badge"><a href="#" style="color:orange"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction(\''.$configType.'\')"></span></a></span>';
结果:
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction(\' project\')"=""></span>
尝试 2:
$html .= '<span class="badge"><a href="#" style="color:orange"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction('.'$configType'.')"></span></a></span>';
结果:
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction(project)"></span>
关闭,但应该是'project'。
期望的结果:
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction('project')"></span>
【问题讨论】:
-
奇怪,我测试时你的第一次尝试成功了。
标签: php html string variables escaping