[backup]str_place简易使用 这有什么好的,一两句话就能解决的还用这么复杂?$temp = file_get_contents($fname);$temp = preg_replace('/\{([0-9a-zA-Z]+)\}/e', '$$1', $temp); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对,最简单的模板解析不是啊,它生成下面的东西$cells = str_replace( "{room_name}", $room_name, $cells );$cells = str_replace( "{products_name}", $products_name, $cells );$cells = str_replace( "{room_img}", $room_img, $cells );$cells = str_replace( "{room_descrip}", $room_descrip, $cells );$cells = str_replace( "{products}", $products, $cells );$cells = str_replace( "{rooms}", $rooms, $cells );$cells = str_replace( "{hotel_name}", $hotel_name, $cells );$cells = str_replace( "{school_name}", $school_name, $cells );$cells = str_replace( "{hotel_img}", $hotel_img, $cells );$cells = str_replace( "{hotel_descrip}", $hotel_descrip, $cells );$cells = str_replace( "{school_img}", $school_img, $cells );$cells = str_replace( "{school_descrip}", $school_descrip, $cells );$cells = str_replace( "{hotels}", $hotels, $cells );$cells = str_replace( "{schools}", $schools, $cells ); 这有什么好的,一两句话就能解决的还用这么复杂?$temp = file_get_contents($fname);$temp = preg_replace('/\{([0-9a-zA-Z]+)\}/e', '$$1', $temp);这个意思是? Meteorlet(www.dictworld.com) 的有点问题吧,他是直接就将{test}换成$test(寒,用单引号来括起的变量,难道也能让php替换为变量的实际值?应该要用双引号吧)不过,他的方法无疑是一个新思路,用一个正规替换代替了楼主的一大堆普通替换 能不能替换,有兴趣的人自己去测试,看不懂的人去看看php.net上关于正则表达式中e模式的介绍。 哦,$l里存放{xxx}群,用$$l来取出变量这样写应该也可以,更容易理解一些。也简洁。$l = array("name","title","descrip");$temp = file_get_contents($fname);$temp = str_replace("{$l}", $$l, $temp);正则有e模式,受教了。 $l是数组,$$l取不出来每个值的,必须循环:for($i=0;$i<count($l);$i++){ $temp = str_replace("{{$l[$i]}}", ${$l[$i]}, $temp);} google的一道面试题目大家来试下 php正则表达式替换链接 php乱码问题 php计算两天日期差时包括天数小时分数 mysql和phpmyadmin乱码 验证码的问题 求教php生成xml前先怎樣清空xml或刪除根節點data 这段extract代码什么意思 【急用】心痛转让“中国图酷网”,个人勿进!!企业不进后悔 如何将VFP数据库中的数据转到MYSQL的数据库中? php连接SQLServer问题 请问在php查询页面中,如何实现上页,下页,首页,尾页跳转功能?
$cells = str_replace( "{room_name}", $room_name, $cells );
$cells = str_replace( "{products_name}", $products_name, $cells );
$cells = str_replace( "{room_img}", $room_img, $cells );
$cells = str_replace( "{room_descrip}", $room_descrip, $cells );
$cells = str_replace( "{products}", $products, $cells );
$cells = str_replace( "{rooms}", $rooms, $cells );
$cells = str_replace( "{hotel_name}", $hotel_name, $cells );
$cells = str_replace( "{school_name}", $school_name, $cells );
$cells = str_replace( "{hotel_img}", $hotel_img, $cells );
$cells = str_replace( "{hotel_descrip}", $hotel_descrip, $cells );
$cells = str_replace( "{school_img}", $school_img, $cells );
$cells = str_replace( "{school_descrip}", $school_descrip, $cells );
$cells = str_replace( "{hotels}", $hotels, $cells );
$cells = str_replace( "{schools}", $schools, $cells );
$temp = preg_replace('/\{([0-9a-zA-Z]+)\}/e', '$$1', $temp);
这个意思是?
不过,他的方法无疑是一个新思路,用一个正规替换代替了楼主的一大堆普通替换
这样写应该也可以,更容易理解一些。也简洁。$l = array("name","title","descrip");
$temp = file_get_contents($fname);
$temp = str_replace("{$l}", $$l, $temp);正则有e模式,受教了。
for($i=0;$i<count($l);$i++)
{
$temp = str_replace("{{$l[$i]}}", ${$l[$i]}, $temp);
}