简体   繁体   English

如何添加 Tinymce 6 在 textarea 中添加 php 代码?

[英]How to add Tinymce 6 add php code in textarea?

how to add a php code in the editor textarea in tinyMCE 6?如何在 tinyMCE 6 的编辑器文本区域中添加 php 代码?

Example: https://i.stack.imgur.com/nCM5x.jpg I need to execute php code in the editor block (page builder dev).示例: https://i.stack.imgur.com/nCM5x.jpg我需要在编辑器块(页面构建器开发)中执行 php 代码。

(my old textarea without tinyMCE working and execute php, tinyMCE not execute and delete the php code in textarea after save) (我没有 tinyMCE 的旧 textarea 工作并执行 php,tinyMCE 不执行并删除 textarea 中的 ZE1BFD762621E409CEE4 代码后)

Thanks for help !感谢帮助 ! Dear Florian亲爱的弗洛里安

you can use the protect attribute of the TinyMCE configuration:您可以使用 TinyMCE 配置的保护属性:

protect: [ /<\?php[\s\S]*?\?>/g // Protect php code ],

or :

Use placeholders in your text, like this:在文本中使用占位符,如下所示:

<h1 class="">__PHPCODE__<h1>

Then before the text is sent to database, replace the placeholders with the variables you want:然后在将文本发送到数据库之前,将占位符替换为您想要的变量:

$yourtext = strtr($yourtext, ['__PHPCODE__' => $title]);

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

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