简体   繁体   中英

Why am I getting this PHP syntax error?

Why am I getting this PHP error ?

I'm printing a piece of code of jQuery in PHP and I get the error:

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');";
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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