以下是网学网为您推荐的PHP-php下正则来匹配dede模板标签的代码,希望本篇文章对您学习有所帮助。
html代码
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
{t:arc row=''10''}
{t:field.title/}
{t:list row=''5''}
{t:field.title/}
{t:list row=''5''}
{t:field.title/}
{/t:list}{t:field.title/}
{/t:list}{t:field.title/}
{/t:arc}
{T:channelartlist
row=''6''
}
<dl>
<dt>{t:field name=''typename''/}{t:field.typename/}</dt>
<dd>
{t:arclist titlelen=''42'' row=''10''}
<ul class=''autod''>
<li>[field:title/]</li>
<li>([field:sendtime function="MyDate(''m-d'',@me)"/])</li>
</ul>
{/t:arclist}
</dl>{/t:channelartlist
}
{t:global.cfg_title
/}{t:var.cfg_title/}{t:global.cfg_webname /}{t:global.cfg_title/}{t:var.cfg_title/}
{t:field.title function="Html2Text(@me)"/}
{t:include
filename="header.htm"/}
{t:include filename="header.htm"
/}
{t:field.title function=''Html2Text(@me)'' }{/t:field
}
{t:array name=''asdas'' }{/t:array
}
{t:channel typeid=''1'' row=''15''}
[field:id/][field:typename/]
{/t:channel
}
{t:channel typeid=''1''} [field:id/] [field:typename/]{/t:channel}
{t:channel typeid=''1'' }[field:id/]
[field:typename/]{/t:channel
}sd
{t:channel}[field:typename/]{/t:channel
}
{t:channel typeid=''1'' row=''20'' }[field:userid/]
[field:scores/]
{/t:channel
}
</body>
</html>
php代码
复制代码 代码如下:
<?php
$str = file_get_contents("test.htm");
$skstr="{";
$skdstr="t:";
$sdstr="}";
//$reg="/{t:.*?(?:\/).*?}/si";//此无法匹配嵌套,只能一层 si s: 使前面的. 包括换行符 i:不区分大小写
//$reg="/({t:*[^{]*\/}|{t:*[^}]*}([^{]|(?R))*{\/t:.*?})/si";无限嵌套都可截取.
$reg=''/(''.$skstr.$skdstr.''*[^''.$skstr.'']*\/''.$sdstr.''|''.$skstr.$skdstr.''*[^''.$sdstr.'']*''.$sdstr.''([^''.$skstr.'']|(?R))*''.$skstr.''\/''.$skdstr.''.*?''.$sdstr.'')/si'';
preg_match_all($reg,$str,$m);
/*echo "<pre>";print_r($m[0]);echo "</pre>";exit();*/
$CTags=array();
$glarr1=array($skstr.$skdstr=>'''');//array(''{t:''=>'''');前缀
$glarr2=array(''"''=>'''',''\''''=>'''',''