解析错误:语法错误,意外'(',期望变量(T_VARIABLE)或'$'

Mia*_*Mia 1 html javascript php jquery

我收到错误,我不知道如何解决它..

错误是:

解析错误:第7行的C:\ xampp\htdocs\records\delete-confirm.php中的语法错误,意外的'(',期望变量(T_VARIABLE)或'$'

第7行是:

echo "<script>$(document).ready(function(){$('.modal-" . $row->id . "').hide();$('#delete-" . $row->id . "').click(function(){$('.modal-" . $row->id . "').show();});$('#cancel-" . $row->id . "').click(function(){$('.modal-" . $row->id . "').hide();});});</script>";
Run Code Online (Sandbox Code Playgroud)

我检查了整条线,但那里似乎没有错误?这里出了什么问题?

mit*_*oft 5

通过"echo语句中使用双引号,PHP 读取引号内的内容的值.单引号' 指定为引号之间的值.

$variable = 'Mia';  // assigns the value Mia to the $variable
echo '$variable';   // output is $variable;
echo "$variable";   // output is Mia;
Run Code Online (Sandbox Code Playgroud)

在您的示例中,用单引号而不是双引号包装文字输出,它将解决您的问题.

echo '<div class="example" id="' . $variable . '">';
Run Code Online (Sandbox Code Playgroud)