Php 表达式引擎/截断-删除a<;预处理>;标签

Php 表达式引擎/截断-删除a<;预处理>;标签,php,expressionengine,truncate,pre,truncation,Php,Expressionengine,Truncate,Pre,Truncation,我正在使用expression engine字段使用 <p class="excerpt">{exp:trunchtml chars="300"}{code_content}{/exp:trunchtml}</p> 下面是一个包含代码的示例条目: $content = $this->EE->TMPL->tagdata; preg_replace('/<pre[^>]*>.*?<\/pre>/i', '', $content

我正在使用expression engine字段使用

<p class="excerpt">{exp:trunchtml chars="300"}{code_content}{/exp:trunchtml}</p>
下面是一个包含代码的示例条目:

$content = $this->EE->TMPL->tagdata;
preg_replace('/<pre[^>]*>.*?<\/pre>/i', '', $content);
return $content;

诸如此类诸如此类的自相矛盾

[code]摄像机位置设置(0,20,35);[/code]
这是一个非常特殊的需求,据我所知,没有任何现有的插件可以做到这一点。你的两个选择是:

创建一个专用的摘录字段(就制作更好的摘录和保持数据结构化而言,这是最好的)

或者,(真的不是很难)你通过考试的内容是什么 对其执行一些
preg\u replace()
,以消除您的
元素及其所有内容,返回清理结果

所以它看起来像这样:

{exp:trunchtml chars=“300”} {exp:my\u plugin:replace\u pre}{code\u content}{/exp:my\u plugin:replace\u pre} {/exp:trunchtml}

这一点PHP将在插件中为您带来魔力:

$content=$this->EE->TMPL->tagdata;
preg_替换('/]*>.*?/i','.$content);
返回$content;
<p class="excerpt">
    {exp:trunchtml chars="300"}
        {exp:my_plugin:replace_pre}{code_content}{/exp:my_plugin:replace_pre}
    {/exp:trunchtml}
</p>
$content = $this->EE->TMPL->tagdata;
preg_replace('/<pre[^>]*>.*?<\/pre>/i', '', $content);
return $content;