php 模板标签入门教程[file_get_content]
本文章是利用了php的fso功能读取模板文件,然后根据我处自定义好的标签进行了文件模板替换就OK了。
本文章是利用了php的fso功能读取模板文件,然后根据我处自定义好的标签进行了文件模板替换就OK了。
function GetContent($type){
if( $type )
{
if(file_exists('./mail_room.html') )
{
$content = file_get_contents( './mail_room.html');
}
else
{
ShowMsg('file can' read fail ');
}
}
else
{
if( file_exists( './mail_person.html') )
{
$content = file_get_contents( './mail_person.html');
}
else
{
ShowMsg('person file read fail!');
}
}
return $content;
}
function template($str)
{
$_url = $_SERVER['HTTP_HOST'];
$_temp = str_replace('{username}',$_SESSION['uname'],$str);
$_temp = str_replace('http://pic4.phprm.com/2013/09/05/[bgpic].jpg',getPic(),$_temp);
$_temp = str_replace('{url}',$_url,$_temp);
return $_temp;
}
我们来看看模板文件
<style type="text/css">
#mail{
font-family:"微软雅黑", "宋体",arial;
font-size:12px;
height:530px;
width:662px;
background:url(http://pic4.phprm.com/2013/09/05/mailback.jpg) no-repeat top left;
}
#photo{
height:380px;
width:630px;
position:absolute;
top:20px;
left:25px;
background:url([bgpic]) no-repeat top left;
}
#photo img{
border:none;
height:380px;
width:630px;
}
#infomation{
padding:5px 0 0 0;
position:absolute;
top:400px;
left:25px;
height:105px;
width:629px;
}
#entry{
margin:10px 0 0 6px;
float:left;
width:108px;
height:90px;
}
#entry ul{
margin: 0;
padding: 0;
}
#entry li{
float:left;
list-style:none;
text-indent:10px;
}
#entry a{
display:block;
height:42px;
width:53px;
}
#cjhd{
background:url(http://pic4.phprm.com/2013/09/05/cjhd.jpg) no-repeat top left;
height:42px;
width:53px;
}
#aygw{
background:url(http://pic4.phprm.com/2013/09/05/aygw.jpg) no-repeat top left;
height:42px;
width:53px;
}
#zdzx{
background:url(http://pic4.phprm.com/2013/09/05/zdzx.jpg) no-repeat top left;
height:42px;
width:53px;
}
#title{
height:21px;
margin:5px 0;
background:url(http://pic4.phprm.com/2013/09/05/title.jpg) no-repeat top left;
}
#artical{
margin:0 0 0 5px;
float:left;
width:180px;
height:105px;
overflow:hidden;
}
#words{
font-size:14px;
height:70px;
line-height:18px;
margin:20px 0 0 0;
}
#words p{
margin:0;
padding:0;
}
#words a{
text-decoration:underline;
color:#be2f60;
}
#artical{
margin:5px 0 0 0px;
}
#artical ul{
padding:0;
margin:5px 0 0 5px;
}
#artical ul li{
list-style:none;
background:url(http://pic4.phprm.com/2013/09/05/dot.jpg) no-repeat 0px 7px;
text-indent:10px;
height:18px;
color:#505050;
float:left;
width:180px;
}
#artical ul li a{
text-decoration:none;
color:#5e5e5e;
}
</style>
</head>
<body>
<div id="mail">
<div id="photo"> </div>
<div id="infomation">
<div id="entry">
<ul>
<li id="cjhd"><a href="#"></a></li>
<li id="zdzx"><a href="#"></a></li>
<li id="aygw"><a href="#"></a></li>
</ul>
</div>
<div id="artical">
<div id="title">
</div>
<ul>
<li><a href="#">新潮食物与儿童疾病的关系 </a></li>
<li><a href="#">不宜喂养宝宝的24种食物 </a></li>
<li><a href="#">育儿饮食错误观点大罗列</a></li>
</ul>
</div>
<div id="words">
<p>{username}说:</p>
<p style="text-indent:20px;"><a href="http://{url}">我发现明星宝宝啦,<br/> 快来一起合影吧!</a></p>
</div>
</div>
</div>
本文地址:http://www.phprm.com/frame/php1004935.html
转载随意,但请附上文章地址:-)