Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌入Jquery/JavaScript时获取PHP错误_Php_Jquery_Parse Error - Fatal编程技术网

嵌入Jquery/JavaScript时获取PHP错误

嵌入Jquery/JavaScript时获取PHP错误,php,jquery,parse-error,Php,Jquery,Parse Error,实际上,我对PHP或JQuery并不特别陌生。这使得这个错误更加奇怪。考虑这两个代码示例。(因为我在这篇文章中用了大约五分钟的时间把它们拼凑在一起,它们既简单又凌乱——但要说明重点。) 及 这两个代码块都会产生此错误: 分析错误:语法错误,第11行中的“(”、预期变量(T_变量)或“$”出现意外 (实际上,第二条写着……第12行——显然) 此代码适用于: <?php print<<<HERE <head> <script src="https:/

实际上,我对PHP或JQuery并不特别陌生。这使得这个错误更加奇怪。考虑这两个代码示例。(因为我在这篇文章中用了大约五分钟的时间把它们拼凑在一起,它们既简单又凌乱——但要说明重点。)



这两个代码块都会产生此错误: 分析错误:语法错误,第11行中的“(”、预期变量(T_变量)或“$”出现意外 (实际上,第二条写着……第12行——显然)

此代码适用于:

<?php
print<<<HERE
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</head>
<p>Error show</p>
<button id="targetbutton" style="height: 60px width: 100px">mouse in</button>
<script>
$("#targetbutton").mouseover(function() {
$("p").css("color", "red")
});
</script>
HERE;
?>

正如我所提到的,我把这个有点混乱和简单的例子放在一起来说明问题。然而,我首先看到了我正在创建的格式良好的网站中的错误——因此代码美——或缺乏代码美——似乎不是问题。)因此出现了三个问题: 1.为什么PHP会抛出关于非PHP代码的错误(第11行在脚本标记中)? 2.为什么PHP会对注释掉的代码抛出错误? 3.为什么移动一个卷曲的大括号会突然解决所有问题? 这个问题是认识论的,但很有趣。

在herdoc(和双引号字符串)中,
{$
引入了一个插值变量或表达式

如果要将内容转储到浏览器,请完全退出PHP模式,或使用NOWDOC:

print <<<'HERE'
Note single-quotes around keyword
You can now have anything you like here and PHP won't try
to mess with it.
HERE;

print这里没有什么奇怪的,它是按照文档记录的方式工作的。请阅读。哇……几乎10年的PHP,从来都不知道{$inherdocs。谢谢!
<?php
print<<<HERE
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</head>
<p>Error show</p>
<button id="targetbutton" style="height: 60px width: 100px">mouse in</button>
<script>
$("#targetbutton").mouseover(function() {
$("p").css("color", "red")
});
</script>
HERE;
?>
print <<<'HERE'
Note single-quotes around keyword
You can now have anything you like here and PHP won't try
to mess with it.
HERE;