如何在DedeCms 标记中运行PHP

如何在织梦DedeCms 标记中运行PHP :   打开 pub_dedetag.php 找到 function AssignSysTag() for函数结束的地方,即是在 CODE:  这个地方 } // //把分析模板输出到一个字符串中,并返回 // function GetResult() [Copy to clipboard]  —————————– 改为如下代码 ——————————— CODE:  //运行PHP接口 if( $CTag->GetAtt("runphp") == "yes" ) { $DedeMeValue = ""; if($CTag->GetAtt("source")==’value’) { $runphp = $this->CTags[$i]->TagValue; } else{ $DedeMeValue = $this->CTags[$i]->TagValue; $runphp = $CTag->GetInnerText(); } $runphp = str_replace(‘@me’,’$DedeMeValue’,$runphp); eval($runphp); $this->CTags[$i]->IsReplace = TRUE; $this->CTags[$i]->TagValue = $DedeMeValue; } } // //把分析模板输出到一个字符串中,并返回 // function GetResult() [Copy to clipboard]  //////////////////////////////////////////// 这样只要在dedecms的标记中加上 runphp=’yes’ 就可以运行PHP语句了 (用@me表示当前标记的值,$DedeMeValue表示最终返回值,里面为纯PHP代码,不能用<? ?>与THML混合) PHP代码放置方式一: {dede:name runphp=’yes’} 这里写PHP代码 {/dede:name} 方式二: 假如你想在include的文件中使用PHP,则加上 source=’value’ {dede:include runphp=’yes’ source=’value’ file=”/} PHP编写的规范为: 一、PHP编码中不需要再加<??>符号; 二、假如想处理当前标记的值(上面第一种情况),使用 @me 表示当前的值; 三、假如直接引入PHP并要获得运行后的值,必须用 $DedeMeValue 表示运行这个PHP后最终返回的值(因此不能用HTML混合的写法)。 例如: {dede:field runphp=’yes’} $aaa=200; $DedeMeValue=100; $DedeMeValue = $aaa;