简体   繁体   English

为什么会出现此PHP语法错误?

[英]Why am I getting this PHP syntax error?

Why am I getting this PHP error ? 为什么会出现此PHP错误?

I'm printing a piece of code of jQuery in PHP and I get the error: 我正在PHP中打印jQuery的一段代码,但出现错误:

Parse error: syntax error, unexpected '' + str + '' (T_CONSTANT_ENCAPSED_STRING),
expecting ',' or ';' in CODE on line 166 Errors parsing CODE

This is my code: 这是我的代码:

echo "$('.fc-day[data-date="' + str + '"]').css('background', 
'url(http://www.hiu.edu/skin/default/images/calendar-event-mark.png) right top
no-repeat');";

You should escape the quotes. 您应该转义报价。 When you are opening a " quote and want to insert a " inside and echo it, you should escape it as \\" 当你打开一个"报价和要插入"内,呼应它,你应该逃避它作为\\"

In your case: 在您的情况下:

echo "$('.fc-day[data-date="' + str + '"]').css('background', 'url(http://www.hiu.edu/skin/default/images/calendar-event-mark.png) right top no-repeat');";

Should be 应该

echo "$('.fc-day[data-date=\"' + str + '\"]').css('background', 'url(http://www.hiu.edu/skin/default/images/calendar-event-mark.png) right top no-repeat');";

You need to add \\ before " in your code, because script thinks you closed the string stream. 您需要在代码中的“之前”添加\\,因为脚本认为您关闭了字符串流。

<?php
   echo "$('.fc-day[data-date=\"' + str + '\"]').css('background', 'url(http://www.hiu.edu/skin/default/images/calendar-event-mark.png) right top no-repeat');";
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM