i'm getting the php error in the following code due to single quotes.
<?PHP $annoc=echo '<div id="announcement" class="announcement'.$rid1.'">
<div id="AContent"><span style="margin:0px 0px 0px 20px;">'.strip_tags($notify).'</span>
<div style="float:right;">
<span class="remind" onclick="announce('.$rid1.','.$userID.','Remind')">
Remind me later</span>
<span class="dont" onclick="announce('.$rid1.','.$userID.','Dont');"> Don't show me this
again</span></div></div></div>';?>
plz let me know what I'm doing wrong?
You need to escape your single quotes with a \\
<?PHP $annoc=echo '<div id="announcement" class="announcement'.$rid1.'">
<div id="AContent"><span style="margin:0px 0px 0px 20px;">'.strip_tags($notify).'</span>
<div style="float:right;">
<span class="remind" onclick="announce('.$rid1.','.$userID.',\'Remind\')">
Remind me later</span>
<span class="dont" onclick="announce('.$rid1.','.$userID.',\'Dont\');"> Don\'t show me this
again</span></div></div></div>';?>
The syntax highlighting on StackOverflow has got one of them.
;"> Don't show again
That apostrophe is breaking out of your string. You need to escape it with a . All single quotes that aren't breaking your string need to be escaped eg
;"> Don\'t show again
You also have unescaped single quotes in your onclick variables as Pete has pointed out in the answers.
You have an apostrophe in your
Don't show me this again
text. You need to escape that character so that it doesn't think you're terminating the string. EG:
Don\'t show me this again
When you have a lot of HTML, like you do in this case, it's usually simpler to add the PHP to your HTML where appropriate, rather than putting your HTML in a string.
This might be cleaner and help reduce errors in the future:
<div id="announcement" class="announcement<?= $rid1 ?>">
<div id="AContent"><span style="margin:0px 0px 0px 20px;"><?= strip_tags($notify) ?></span>
<div style="float:right;">
<span class="remind" onclick="announce(<?= $rid1 ?>,<?= $userID ?>,'Remind')">
Remind me later</span>
<span class="dont" onclick="announce(<?= $rid1 ?>,<?= $userID ?>,'Dont');"> Don't show me this again</span></div></div></div>
<?php
$annoc = echo '<div id="announcement" class="announcement'.$rid1.'">
<div id="AContent"><span style="margin:0px 0px 0px 20px;">'.strip_tags($notify).'</span>
<div style="float:right;">
<span class="remind" onclick="announce('.$rid1.','.$userID.',\'Remind\')">
Remind me later</span>
<span class="dont" onclick="announce('.$rid1.','.$userID.',\'Dont\');"> Don\'t show me this again</span></div></div></div>';
?>
That is pretty messed up imo.
Maybe useful for you: If you use double quotes you don't have to make extensive use of quotes.
compare:
echo "i speak $myLanguageCount languages";
echo 'i speak '.$myLanguageCount.' languages';
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.