PHP echo 不能在其中使用 HTML


php echo not working with html in it

我希望我的php在用户提交时打印一些东西。

解析错误:语法错误,意外的"javascript"(T_STRING), 期望在 中出现","或";" /homepages/31/d585123241/htdocs/test/xe5/form.php 在第 9 行

这是我的代码,我该怎么做才能修复它:

<?php
echo "$ret bytes written to file<a href ="javascript:history.go(-1)">go back</a>";

在字符串中使用单引号

echo "$ret bytes written to file<a href ='javascript:history.go(-1)'>go back</a>";
改为将

字符串括在单引号中。

echo $ret.' bytes written to file<a href ="javascript:history.go(-1)">go back</a>';

更新:

有多种方法可以解决此问题:

  1. 在每个@SQL技巧答案的字符串中使用单引号
  2. 将字符串括在单引号中,如本答案中最初所示。 这需要连接 PHP 变量。
  3. 转义字符串
    内的双引号 echo "$ret bytes written to file<a href ='"javascript:history.go(-1)'">go back</a>";

我相信其他解决方案是可能的,但最有价值的方法是了解 PHP 字符串和一般的字符串操作/函数。 一个好的起点是:http://php.net/manual/en/language.types.string.php