【发布时间】:2026-01-07 14:10:01
【问题描述】:
好吧,我正在尝试回显一些代码行,但它同时使用了"" 和''。
据我所知,如果您使用"" 启动回显,每次使用"" 时都会停止回显。
如何打印这行代码而不破坏它? 这是我目前拥有的:
echo "<a class='lightbox' href='img/projects/generic/project-16.jpg' data-plugin-options='{'type':'image', 'mainClass': 'mfp-with-zoom', 'zoom': {'enabled': true, 'duration': 300}}'>";
data-plugin-options='{'type':'image', 'mainClass': 'mfp-with-zoom', 'zoom': {'enabled': true, 'duration': 300}}' 是给我带来麻烦的那个,因为我不能使用“”,也不能使用 '',因为一个会破坏回声,另一个会破坏标签。
希望你们能帮助我理解和解决这个小问题,提前非常感谢!
【问题讨论】:
-
在 PHP 字符串上下文中转义引号是用反斜杠
\"完成的。对于 HTML 上下文,您应该应用htmlspecialchars,甚至可能使用json_encode而不是文字。