[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);} 如何给网页内容(设置会员等级) php 用ajax局部隐藏的问题 请教一个去除“[]”的小问题,急!急! PHP学习 关于脚本响应慢的原因 求开源论坛系统 请问一个httpd.ini的规则……总出错!哎! 长跪求助:如何用PHP SHOW一个信息窗口? 如何获取服务器的时间? 大侠门,帮帮忙吧 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);
}