#支持流程中混合处理,原理:把所有内容看作一个不分割的phpcode
#不支持[php]=\$var[/php]输出,要用echo("\$var")来输出。
#修正语句错误时,DIY失效问题。
function sxx_block_display_batch($bid)
{
$mixed_code=block_fetch_content($bid);
#手动取类型,全局的有时候不好用。
$sql="select blockclass from ".DB::table("common_block")." where bid=$bid";
$query=DB::query($sql);
if($row=DB::fetch($query))
{
$blockclass=$row['blockclass'];
}else
{
echo ("no block id:$bid,Please check your database.");
echo ($mixed_code);
return;
};
if(
$blockclass=="html_html" #只处理自定义HTML模块
&& ($_GET['diy']!="yes") #支持DIY当语句错误时可以修改
)
{
#不用[html][/html]了html直接写
$mixed_code=preg_replace("/\[html\]|\[\/html\]/i","",$mixed_code);
$phpmark1="/?"; #可以采取两种书写方式 /? phpcode ?/ 或者 [php] phpcode [/php]
$phpmark1end="?/";
$phpmark2="[php]";
$phpmark2end="[/php]";
$phpmark= (stripos($mixed_code,$phpmark1,0) ? $phpmark1:$phpmark2);
$phpmarkend = ( stripos($mixed_code,$phpmark1,0) ? $phpmark1end:$phpmark2end ) ;
$phpmarkslen= ( stripos($mixed_code,$phpmark1,0) ? 2:5 );
$phpmarkelen= ( stripos($mixed_code,$phpmark1,0) ? 2:6 );
$spos=0;
$epos=0;
$mixed_cool="";
do
{
$epos=stripos($mixed_code,$phpmark,$spos);
if($epos!==false)
{
//有头部HTML?
$html_code=substr($mixed_code,$spos,$epos-$spos);
$mixed_cool.="echo('$html_code');";
//获取PHP代码
$spos=$epos+$phpmarkslen;
$epos=stripos($mixed_code,$phpmarkend,$spos);
if($epos!==false)
{
$php_code=substr($mixed_code,$spos,$epos-$spos);
$spos=$epos+$phpmarkelen;
$mixed_cool.=$php_code;
}else
{
echo("error!no php_end_mark.");
echo($mixed_code);
return;
};
}else
{
//有尾部HTML?
$html_code=substr($mixed_code,$spos);
$mixed_cool.="echo('$html_code');";
};
}while($epos!==false);
eval($mixed_cool);
}
else
{
echo($mixed_code);
};
};
测试代码:
Cool Thing:
/?
\$sql="select * from ".DB::table("common_block");
\$query=DB::query(\$sql);
while(\$row=DB::fetch(\$query))
{
echo("\$row[blockclass]");
?/
/?
};
?/
Cool Thing Is It?