$db=mysql_pconnect("127.0.0.1","root","");
mysql_select_db('temp');             
mysql_query("set names gbk");class replace_tag{
var $resultset;
var $tags_arr;
var $mob;   
var $bol=0;

function replace_tag($mob)
{
$this->mob=$mob;
}
public function get_tags($arr)
{
$arr=explode(",",$arr);
for($i=0;$i<count($arr);$i++)
{
$this->tags_arr[$i]=explode(":",$arr[$i]);
}
$this->bol=1;
}

private function tags_2($str)
{
preg_match_all("/\[tag_(.*)\]/isU",$str,$str_array);
for($i=0;$i<count($str_array[0]);$i++)
{
$this->tags_arr[$i][0]=$str_array[0][$i];
$this->tags_arr[$i][1]=$str_array[1][$i];
}

}
public function get_resultset($result)
{
$this->resultset=$result;
}
 
function tag_list($tag,$_tag)
{
$Zstr="";
$tag=preg_quote($tag,"/");
$_tag=preg_quote($_tag,"/");
preg_match("/$tag(.*)$_tag/isU",$this->mob,$str_array);
if($this->bol==0)
{
$this->tags_2($str_array[1]);
                            
}
while($row=mysql_fetch_assoc($this->resultset))
{
$temp=$str_array[1];
for($i=0;$i<count($this->tags_arr);$i++)
{
$temp=str_replace($this->tags_arr[$i][0],${"row"}[$this->tags_arr[$i][1]],$temp); 

}
$Zstr.=$temp;
}
$this->mob=preg_replace("/$tag(.*)$_tag/isU",$Zstr,$this->mob);
$this->bol=0;
}



public function mob()
{
return  $this->mob;
}}
$mob=file_get_contents("list.html");
$obtag=new replace_tag($mob);
$obtag->get_resultset(mysql_query("SELECT  * from temp_image   where 1"));
$obtag->get_tags("[list_lj]:id,[biao_ti]:name");// 可以自己设定
$obtag->tag_list("[list]","[/list]");
$mob=$obtag->mob();$fh=fopen("list___1.html","w");
fwrite($fh,$mob);