为什么我的文章中的 PHP 被字面解释为字符串而不是 PHP?
我正在尝试找到一种在我的文章中使用 Joomla(目前使用 1.5)编写纯 PHP 的方法。到目前为止,我最接近的是使用一个名为 Sourcerer 的插件(查看链接)
问题是 PHP 代码实际上被呈现为 HTML。当我通过 Sourcerer 编辑器编写以下代码时:
<?php echo "Hello world"; ?>
这就是文章中所写的内容:
<span><</span>?php echo "Hello world"; ?<span>></span>
我担心,如果我想出更复杂的代码,在某些时候这会破坏我的 PHP。这也使得代码难以阅读。最后,Sourcerer 的问题是您只能插入新代码,无法编辑之前添加的内容。
有人知道如何将纯 PHP 写入文章吗?
我想坚持这样一个事实:它必须在文章中。我已经找到了一种在模块或组件中执行此操作的方法,例如使用 Jumi。
I am trying to find a way to write pure PHP in my articles with Joomla (currently using 1.5). The closest I got so far was to use a plugin called Sourcerer (see link)
The issue is that the PHP code is actually being rendered as HTML. When I write the below code via the Sourcerer editor:
<?php echo "Hello world"; ?>
This is what is being written to the article:
<span><</span>?php echo "Hello world"; ?<span>></span>
I am afraid that at some point this is going to break my PHP if I come up with more complex code. Also this makes the code hardly readable. Finally the issue with Sourcerer is that you can only insert new code, you can't edit what you previously added.
Does anybody know a way to write pure PHP into articles?
I would like to insist on the fact that it has to be within articles. I already found a way to do it in modules or components, for instance with Jumi.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经使用过 Sourcerer 几次,它确实允许我毫无问题地将 PHP 片段插入到文章中。如果你的 php 被渲染为 html,听起来 php 没有被解析为 php - 首先要确保 sourcerer 插件确实已启用,以便它可以允许解析你的 php 脚本。 (在此处检查插件启用状态:扩展->插件管理器->sourcerer)。
另外,在添加 PHP 脚本时,请使用 WYSIWYG 编辑器底部的 sourcerer(“插入代码”)按钮 - 它可以保持格式/语法突出显示,并确保使用
{source} {/source 正确转义}
标签。I have used Sourcerer a couple of times and it does allow one to insert PHP snippets into articles without issues. If your php is being rendered as html, it sounds like the php isn't getting parsed as php - first thing is to make sure that the sourcerer plugin is indeed enabled so it can allow your php scripts to get parsed. (check plugin enabled status here: extensions->plugin manager->sourcerer).
Also, use the sourcerer ("Insert Code") button at the bottom of your WYSIWYG editor when adding your PHP scripts - it keeps the formatting/syntax highlighting and ensures that it is escaped properly with the
{source} {/source}
tags.更新,我对 joomla 3.x、sourcerer 有同样的问题,我尝试过tinymice、JCKEDidor 和 JCEEditor。我现在已经放弃这个方法了。
为了将 php 代码插入到文章中,我使用了 php 包含文件,并且所有 html 都在该 php 包含文件中回显。然后从文章编辑器中引用该 php 文件。
那些比我更精通 joomla 的人无疑会使用模块等正确地完成此操作。
An update, I have the same issue with joomla 3.x, sourcerer, I have tried tinymice, JCKEdidor and JCEEditor. I have now given up with this method.
To insert php code into an article I have used a php include file and all the html is echoed inside this php include file. The php file is then referenced from within the Article Editor.
Those more proficient than me with joomla will no doubt do this correctly using a module or the like.
您可以尝试另一个名为 Direct PHP 的插件。它很好用而且简单。只需下载并安装它并确保它已启用。之后开始在 joomla 文章中编写 php 代码。
示例:
它支持几乎所有 PHP 函数,您可以从其设置中过滤掉不需要的函数。
这是下载链接。
You can try another plugin called Direct PHP. It's nice and simple to use. Just download and install it and make sure it is enable. After this start writing your php code in joomla article.
Example:
it supports all most every PHP functions and you can filter the functions what you don't need it from its settings.
Here is the link for the download.
下载&导入插件sourcerer https://extensions.joomla.org/extension/sourcerer/
使用此。对我来说很好。
Download & import plugin sourcerer https://extensions.joomla.org/extension/sourcerer/
use this. It fine for me.