解析错误中带有单引号错误的单引号:语法错误、意外的“Are”(T_STRING)、预期出现“”,“”或“;”

  • 本文关键字:错误 单引号 STRING Are 语法 意外 php html
  • 更新时间 :
  • 英文 :

echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';

我在单引号上遇到问题。解析错误:语法错误、意外的"Are"(T_STRING)、预期 '","' 或 ';' 我尝试更改

echo '<a href="url_to_delete" onclick="return confirm('.'Are you sure want to delete'.') ;">Delete</a>';

但是弹出的confimation不起作用。我需要在 PHP 中使用单引号,但不需要在双引号上使用。

您需要使用反斜杠转义单引号:

echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';

你的问题之一是你没有转义字符串中的引号。

echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';

另一个是你正在回显纯html,你可以退出php模式并简单地输出html

...
?>
<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>
<?php
...

最新更新