无法让PHP在HTML中的标签内执行[复制]

时间:2022-05-18 06:53:26

This question already has an answer here:

这个问题在这里已有答案:

I am using this procedure that reads my local reference bibtex file and automatically formats them inside my HTML page. The procedure is fairly straightforward but something somewhere is not working and after a LOT of debugging I cannot figure it out.

我正在使用此过程读取我的本地参考bibtex文件并自动在我的HTML页面中格式化它们。这个过程相当简单,但是某些地方不能正常工作,经过大量的调试我无法理解。

After spending quite some time on this, I have zeroed down the problem to this area in my code:

在花了相当长的时间之后,我在我的代码中将问题归结为这个区域:

...
...
<textarea hidden name="bibtex_input" id="bibtex_input" cols=50 rows=20>
    <?php echo file_get_contents("ref.bib"); ?>
</textarea>

<div id="bibtex_errors"></div>
<div class="bibtex_template">
    <li>
        <a class="url"><span class="title"></span></a><br>
        <span class="author"></span><br>
        <span class="booktitle"></span>
        <span class="if publisher">
            <span class="publisher"></span>.
        </span>
        <span class="if pages">
          p. <span class="pages"></span>.
        </span>
        <span class="if year">
            <span class="year"></span></span>
        <br>
        <a class="bibtexCodeLink">
            [bibtex]
        </a>
        <br><br>
     </li>
</div>

<ol id="bibtex_display">
</ol>

    </td>
</tr>
<tr>
    <td>
        <hr />
    </td>
</tr>
</table>
</body>
</html>

Seems like PHP cannot execute inside the textarea tags for some reason. Outside the textarea tags PHP echoes the contents of the file just fine and I can see it on the page. In any case when php is used inside the textarea tags, I cannot see the formatted output on my HTML page and instead see this.

似乎PHP由于某种原因无法在textarea标签内执行。在textarea标签之外,PHP回应文件的内容就好了,我可以在页面上看到它。在任何情况下,当在textarea标签内使用php时,我无法在HTML页面上看到格式化的输出,而是看到了这一点。

无法让PHP在HTML中的标签内执行[复制]

This is what it should look like.

这应该是它的样子。

无法让PHP在HTML中的标签内执行[复制]

What I have tried:

我试过的:

  • PHP is working. phpinfo() shows me the PHP version when PHP is invoked anywhere else on the page.

    PHP正在运行。 phpinfo()向我展示了在页面上的其他任何位置调用PHP时的PHP版本。

  • JS script, jquery and stylesheet mentioned on the page above is included in the header.

    上面提到的JS脚本,jquery和样式表都包含在标题中。

  • Scripts, html, php files, stylesheets all have proper 644 or 755 chmod on them. So it shouldn't be a permissions issue(?)

    脚本,HTML,PHP文件,样式表都有适当的644或755 chmod。所以它不应该是权限问题(?)

  • The page itself is saved as .php and not 'html'.

    页面本身保存为.php而不是'html'。

  • The 'ref.bib' file's contents are proper and have been tested on the website I linked above. It should work.
  • 'ref.bib'文件的内容是正确的,并已在我上面链接的网站上测试过。它应该工作。
  • Used this website to validate my HTML. My HTML syntax should be free of errors.
  • 使用此网站验证我的HTML。我的HTML语法应该没有错误。
  • Console shows me this:

    控制台告诉我这个:

    jQuery.Deferred exception: $(...).size is not a function @http://mywebsite.edu/~me/group/bibtextohtml.js:446:9 l@https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29373 a/https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29677 undefined

    jQuery.Deferred异常:$(...)。size不是函数@http://mywebsite.edu/~me/group/bibtextohtml.js:446:9 l @ https://ajax.googleapis.com/ ajax / libs / jquery / 3.3.1 / jquery.min.js:2:29373 a / https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29677未定义

    TypeError: $(...).size is not a function[Learn More]

    TypeError:$(...)。size不是函数[了解更多]

Question:

题:

How can I get it to work like it shows on the website linked above? Is it a problem with PHP inside textarea tags or something else?

如何让它像上面链接的网站上显示的那样工作? PHP内部的textarea标签或其他东西是一个问题吗?

3 个解决方案

#1


1  

After help from the community here and after some experimentation according to comments made, I was able to look at the developer console in browser and see that the jquery was giving errors. In short, I was using the latest version of jquery (3.x) and the tool (that I took from the website linked in my question) was using a function that is deprecated. I went on the page, looked at their source, and used their specific version of jquery. It works now.

在社区的帮助下,根据评论做了一些实验后,我能够在浏览器中查看开发人员控制台,看到jquery出错了。简而言之,我使用的是最新版本的jquery(3.x),并且该工具(我从我的问题链接的网站中获取)使用的是不推荐使用的函数。我进入页面,查看了他们的源代码,并使用了他们特定版本的jquery。它现在有效。

Alternatively, I also tested updating the deprecated size() function to .length and it now works with the latest jquery.

或者,我还测试了将已弃用的size()函数更新为.length,现在它可以使用最新的jquery。

For more info, see this: g.size() is not a function - Jquery Error

有关更多信息,请参阅:g.size()不是函数 - Jquery错误

#2


-1  

Procedural PHP is as intelligent as an hammer so I'm pretty sure that if there's any content it is displayed despite of it's adherence with HTML. It not even bother about if there is any html within the page unless you don't tell it to.

程序性PHP就像锤子一样聪明,所以我很确定如果有任何内容,尽管它遵守HTML,它仍会被显示出来。除非你不告诉它,否则它甚至不会打扰页面中是否有任何HTML。

It could seem trivial but please check the page source generated with right click->View Page Source and check there and not with just the inspector.

这看起来似乎微不足道,但请检查右键单击 - >查看页面源生成的页面源,并检查那里,而不是只检查器。

Textarea allows only plain text and I think that anything else (e.g. html strings) is just discarded by your browser.

Textarea只允许纯文本,我认为其他任何东西(例如html字符串)都会被您的浏览器丢弃。

#3


-1  

Your code has the correct structure. There are closing tags that confused your textarea tags.

您的代码具有正确的结构。有关闭标签会混淆textarea标签。

<textarea ...>
<?php echo htmlspecialchars(file_get_contents('...'));?>
</textarea>

#1


1  

After help from the community here and after some experimentation according to comments made, I was able to look at the developer console in browser and see that the jquery was giving errors. In short, I was using the latest version of jquery (3.x) and the tool (that I took from the website linked in my question) was using a function that is deprecated. I went on the page, looked at their source, and used their specific version of jquery. It works now.

在社区的帮助下,根据评论做了一些实验后,我能够在浏览器中查看开发人员控制台,看到jquery出错了。简而言之,我使用的是最新版本的jquery(3.x),并且该工具(我从我的问题链接的网站中获取)使用的是不推荐使用的函数。我进入页面,查看了他们的源代码,并使用了他们特定版本的jquery。它现在有效。

Alternatively, I also tested updating the deprecated size() function to .length and it now works with the latest jquery.

或者,我还测试了将已弃用的size()函数更新为.length,现在它可以使用最新的jquery。

For more info, see this: g.size() is not a function - Jquery Error

有关更多信息,请参阅:g.size()不是函数 - Jquery错误

#2


-1  

Procedural PHP is as intelligent as an hammer so I'm pretty sure that if there's any content it is displayed despite of it's adherence with HTML. It not even bother about if there is any html within the page unless you don't tell it to.

程序性PHP就像锤子一样聪明,所以我很确定如果有任何内容,尽管它遵守HTML,它仍会被显示出来。除非你不告诉它,否则它甚至不会打扰页面中是否有任何HTML。

It could seem trivial but please check the page source generated with right click->View Page Source and check there and not with just the inspector.

这看起来似乎微不足道,但请检查右键单击 - >查看页面源生成的页面源,并检查那里,而不是只检查器。

Textarea allows only plain text and I think that anything else (e.g. html strings) is just discarded by your browser.

Textarea只允许纯文本,我认为其他任何东西(例如html字符串)都会被您的浏览器丢弃。

#3


-1  

Your code has the correct structure. There are closing tags that confused your textarea tags.

您的代码具有正确的结构。有关闭标签会混淆textarea标签。

<textarea ...>
<?php echo htmlspecialchars(file_get_contents('...'));?>
</textarea>