简体   繁体   English

php heredoc-不回显&#39; <script type=“text/javascript”>'

[英]php heredoc — not echoing '<script type=“text/javascript”>'

I've used heredoc syntax in server-side php to clean up the code -- my understanding of the utility of heredoc is "allows you to send client-side code to the browser and avoid individual echo's for each browser-side code statement" 我在服务器端php中使用了Heredoc语法来清理代码-我对Heredoc实用程序的理解是“允许您将客户端代码发送到浏览器,并避免每个浏览器端代码语句的单独回显”

My understanding of heredoc is that it just makes it easier to encapsulate a chunk of code you need to send to the browser without having to write an explicit 'echo' on every line, basically "Ok web server -- between the '<<<' and the end of the heredoc, all this should be sent to the browser." 我对heredoc的理解是,它使封装需要发送到浏览器的代码块变得更加容易,而不必在每行中写一个显式的“ echo”,基本上是“ Ok Web服务器-'<<< ”和Heredoc的末尾,所有这些都应发送到浏览器。”

So I'm not sure why I'm getting syntax errors for the following code: 所以我不确定为什么为什么以下代码会出现语法错误:

 <?php
 echo <<<_SENDITALL 
 <script type="text/javascript">
 function foo(theArg1, theArg2, theArg3)
 {
 }
 </script>
 _SENDITALL;
 ?>

I've got heredocs all over the place in my project and they work fine so I'm not understanding why my Netbeans IDE keeps flagging the above with syntax errors. 我的项目中到处都有heredocs,它们都可以正常工作,所以我不明白为什么我的Netbeans IDE总是用语法错误来标记上面的内容。

For example, I use heredoc to send forms to the browser. 例如,我使用heredoc将表单发送到浏览器。 And I've got javascript doing input validation on my html forms, with 'onsubmit' and 'onblur' etc. 而且我已经用javascript在HTML表单上执行输入验证,包括“ onsubmit”和“ onblur”等。

So surely it can't be that php is of the mind "See here, it's fine if you heredoc html script to the browser, but your attempt to heredoc some client-side javascript will not stand' -- that wouldn't make sense both html and javascript are client-side, why would the heredoc syntax "care" whether html script or javascript was being sent to the browser. 因此,可以肯定的是,php并不是头脑“请看这里,如果您将html脚本添加到浏览器中就可以了,但是您尝试使用客户端javascript的尝试将不会成功”-这没有任何意义。 html和javascript都是客户端,为什么无论将html脚本还是javascript发送到浏览器,heredoc语法都“关心”。

There is a space after echo <<<_SENDITALL , remove it. echo <<<_SENDITALL后有一个空格,将其删除。

There also is a space before _SENDITALL; _SENDITALL;之前还有一个空格_SENDITALL; .

I'm not sure if it exists inside the original code(may come from the formatting here), remove it too. 我不确定它是否存在于原始代码中(可能来自此处的格式),也可以将其删除。

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

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