开发者

Why is my PHP in articles being interpreted literally as a string instead of as PHP?

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>&lt;</span>?php echo "Hello world"; ?<span>&gt;</span>

I am afraid that at some point this is going to break my PHP if I come up with more complex code. Als开发者_Go百科o 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.


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.


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.


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:

<?php
  echo "Hello World!";
?>

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.


Download & import plugin sourcerer https://extensions.joomla.org/extension/sourcerer/

{source} [[?php echo "Hello world"; ?]] {/source}

use this. It fine for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜