日期:2014-05-17 浏览次数:20504 次
<?php
class IndexAction extends YouYaX
{
public function index()
{
header("Content-type: text/html; charset=utf-8");
$this->assign("csdn","csdner,大家中午好")
->assign("head",array("来自","xxx"))
->assign("greet",array("<h2>PHP技术</h2>","基础编程","开放资源","framework"))
->assign("foot",array(
array("id"=>'1',"foot"=>"这是底部测试1"),
array("id"=>'2',"foot"=>"这是底部测试2"),
array("id"=>'3',"foot"=>"这是底部测试3")
))
->assign("bye","88,good bye");
$this->display("index.html");
}
}
?>
<html>
<head>
<title>welcome YouYaX</title>
</head>
<body>
<center>
<table width="400" >
<!-- 普通替换 -->
<tr>
<td>{csdn}</td>
</tr>
<!-- 一维数组替换 -->
<tr>
<td><loop> {head} ———— </loop> 发表在【{greet->1}】</td>
</tr>
</tr>
<!-- 一维数组替换 -->
<loop>
<tr><td>{greet}</td></tr>
</loop>
</table>
<hr>
<!-- 二维数组替换 -->
<list>
<h3>
{foot.foot}
</h3>
</list>
<!-- 普通替换 -->
{bye}
<hr>
比较测试 , 让我们在html中使用PHP吧 , 模板变量上要写上双引号 <br>
<?php
if( "{bye}"=="88,good bye" ){
echo "<font color=red>看吧 , 果然正确吧, 测试结束,测试者:{head->1}</font>";
}else{
echo "错了";
}
?>
</center>
</body>
</html>
//——普通替换
//单个输出数组值
// var_dump($this->array_array);exit;
$return=preg_match_all('/\{[^{]*->[^{}]*}/',$txt,$single);
if($return){
foreach($single[0] as $v){
$x=strlen($v);
$y=$x-2;
$z=substr($v,1,$y); //title->0
$z1 = preg_split('/->/', $z, -1, PREG_SPLIT_NO_EMPTY);
$txt=str_replace($v,$this->array_array[$z1[0]][$z1[1]],$txt);
}
}
//数组替换
$return=preg_match_all("/<\s*loop\s*>\s*(.+?)\s*<\s*\/loop\s*>/s",$txt,$match);
if($return){
try{
foreach($match[1] as $lv){
if(eregi("<\s*loop\s*>",$lv)){
throw new Exception(htmlspecialchars("<loo