人们可以很好地看到我的网站,但谷歌收到了500个错误。我打开了所有的错误报告,结果是:第6行出现意外的"{",应为","或";"。
我已经看了很多次了,没有发现任何错误。希望有人能帮忙。如果我选择第5行,即$('''#js_terms_of_use''')。单击(function()并删除这两个''',第6行的错误就会消失,但我逃脱了它们,所以我不明白问题是什么。下面是代码:
echo '
<script type='"text/javascript'">
$Behavior.termsAndPrivacy = function()
{
$(''#js_terms_of_use'').click(function()
{
'; ?>
tb_show('<?php echo extras::getPhrase('user.terms_of_use', array('extras_squote' => true)); ?>', $.ajaxBox('page.view', 'height=410&width=600&title=terms'));
<?php echo '
return false;
});
$(''#js_privacy_policy'').click(function()
{
'; ?>
tb_show('<?php echo extras::getPhrase('user.privacy_policy', array('extras_squote' => true)); ?>', $.ajaxBox('page.view', 'height=410&width=600&title=policy'));
<?php echo '
return false;
});
}
</script>
';
默认情况下,<?php ?>
标记之外的任何内容都会被回显。利用这个优势。多行单引号字符串是个坏主意。以下是清理代码的尝试:
<?php
$TOU = extras::getPhrase('user.terms_of_use', array('extras_squote' => true));
$priv = extras::getPhrase('user.privacy_policy', array('extras_squote' => true));
?>
<script type="text/javascript">
$Behavior.termsAndPrivacy = function()
{
$('#js_terms_of_use').click(function()
{
tb_show('<?php echo $TOU ?>', $.ajaxBox('page.view', 'height=410&width=600&title=terms'));
return false;
});
$('#js_privacy_policy').click(function()
{
tb_show('<?php echo $priv ?>', $.ajaxBox('page.view', 'height=410&width=600&title=policy'));
return false;
});
}
</script>
如果您真的需要在PHP中从单个echo输出多行,请使用heredoc语法(如果可用,请使用newdoc语法)。要了解更多信息,请访问php.net