php 模板标签入门教程[file_get_content]
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('[bgpic]',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://111cn.net/emailimages/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://111cn.net/emailimages/cjhd.gif) no-repeat top left;
height:42px;
width:53px;
}
#aygw{
background:url(http://111cn.net/emailimages/aygw.gif) no-repeat top left;
height:42px;
width:53px;
}
#zdzx{
background:url(http://111cn.net/emailimages/zdzx.gif) no-repeat top left;
height:42px;
width:53px;
}
#title{
height:21px;
margin:5px 0;
background:url(http://111cn.net/emailimages/title.gif) 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(111cn.net/emailimages//emailimages/dot.gif) 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>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无刷新文件上传系统</title>
</head>
<body>
<style>
.fu_list {
width:600px;
background:#ebebeb;
font-size:12px;
}
.fu_list td {
padding:5px;
line-height:20px;
background-color:#fff;
}
.fu_list table {
width:100%;
border:1px solid #ebebeb;
}
.fu_list thead td {
background-color:#f4f4f4;
}
.fu_list b {
font-size:14px;
}
/*file容器样式*/
a.files {
width:90px;
height:30px;
overflow:hidden;
display:block;
border:1px solid #BEBEBE;
background:url(img/fu_btn.gif) left top no-repeat;
text-decoration:none;
}
a.files:hover {
background-color:#FFFFEE;
background-position:0 -30px;
}
/*file设为透明,并覆盖整个触发面*/
a.files input {
margin-left:-350px;
font-size:30px;
cursor:pointer;
filter:alpha(opacity=0);
opacity:0;
}
/*取消点击时的虚线框*/
a.files, a.files input {
outline:none;/*ff*/
hide-focus:expression(this.hideFocus=true);/*ie*/
}
</style>
<form id="uploadForm" action="File.php">
<table border="0" cellspacing="1" class="fu_list">
<thead>
<tr>
<td colspan="2"><b>上传文件</b></td>
</tr>
</thead>
<tbody>
<tr>
<td align="right" width="15%" style="line-height:35px;">添加文件:</td>
<td><a href="javascript:void(0);" class="files" id="idFile"></a> <img id="idProcess" style="display:none;" src="img/loading.gif" /></td>
</tr>
<tr>
<td colspan="2"><table border="0" cellspacing="0">
<thead>
<tr>
<td>文件路径</td>
<td width="100"></td>
</tr>
</thead>
<tbody id="idFileList">
</tbody>
</table></td>
</tr>
<tr>
<td colspan="2" style="color:gray">温馨提示:最多可同时上传 <b id="idLimit"></b> 个文件,只允许上传 <b id="idExt"></b> 文件。 </td>
</tr>
<tr>
<td colspan="2" align="center" id="idMsg"><input type="button" value="开始上传" id="idBtnupload" disabled="disabled" />
<input type="button" value="全部取消" id="idBtndel" disabled="disabled" />
</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
var isIE = (document.all) ? true : false;
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}
var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
//文件上传类
var FileUpload = Class.create();
FileUpload.prototype = {
//表单对象,文件控件存放空间
initialize: function(form, folder, options) {
this.Form = $(form);//表单
this.Folder = $(folder);//文件控件存放空间
this.Files = [];//文件集合
this.SetOptions(options);
this.FileName = this.options.FileName;
this._FrameName = this.options.FrameName;
this.Limit = this.options.Limit;
this.Distinct = !!this.options.Distinct;
this.ExtIn = this.options.ExtIn;
this.ExtOut = this.options.ExtOut;
this.onIniFile = this.options.onIniFile;
this.onEmpty = this.options.onEmpty;
this.onNotExtIn = this.options.onNotExtIn;
this.onExtOut = this.options.onExtOut;
this.onLimite = this.options.onLimite;
this.onSame = this.options.onSame;
this.onFail = this.options.onFail;
this.onIni = this.options.onIni;
if(!this._FrameName){
//为每个实例创建不同的iframe
this._FrameName = "uploadFrame_" + Math.floor(Math.random() * 1000);
//ie不能修改iframe的name
var oFrame = isIE ? document.createElement("<iframe name="" + this._FrameName + "">") : document.createElement("iframe");
//为ff设置name
oFrame.name = this._FrameName;
oFrame.style.display = "none";
//在ie文档未加载完用appendChild会报错
document.body.insertBefore(oFrame, document.body.childNodes[0]);
}
//设置form属性,关键是target要指向iframe
this.Form.target = this._FrameName;
this.Form.method = "post";
//注意ie的form没有enctype属性,要用encoding
this.Form.encoding = "multipart/form-data";
//整理一次
this.Ini();
},
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
FileName: "Files[]",//文件上传控件的name,配合后台使用
FrameName: "",//iframe的name,要自定义iframe的话这里设置name
onIniFile: function(){},//整理文件时执行(其中参数是file对象)
onEmpty: function(){},//文件空值时执行
Limit: 10,//文件数限制,0为不限制
onLimite: function(){},//超过文件数限制时执行
Distinct: true,//是否不允许相同文件
onSame: function(){},//有相同文件时执行
ExtIn: ["gif","jpg","rar","zip","iso","swf","exe"],//允许后缀名
onNotExtIn: function(){},//不是允许后缀名时执行
ExtOut: [],//禁止后缀名,当设置了ExtIn则ExtOut无效
onExtOut: function(){},//是禁止后缀名时执行
onFail: function(){},//文件不通过检测时执行(其中参数是file对象)
onIni: function(){}//重置时执行
};
Extend(this.options, options || {});
},
//整理空间
Ini: function() {
//整理文件集合
this.Files = [];
//整理文件空间,把有值的file放入文件集合
Each(this.Folder.getElementsByTagName("input"), Bind(this, function(o){
if(o.type == "file"){ o.value && this.Files.push(o); this.onIniFile(o); }
}))
//插入一个新的file
var file = document.createElement("input");
file.name = this.FileName; file.type = "file"; file.onchange = Bind(this, function(){ this.Check(file); this.Ini(); });
this.Folder.appendChild(file);
//执行附加程序
this.onIni();
},
//检测file对象
Check: function(file) {
//检测变量
var bCheck = true;
//空值、文件数限制、后缀名、相同文件检测
if(!file.value){
bCheck = false; this.onEmpty();
} else if(this.Limit && this.Files.length >= this.Limit){
bCheck = false; this.onLimite();
} else if(!!this.ExtIn.length && !RegExp(".(" + this.ExtIn.join("|") + ")$", "i").test(file.value)){
//检测是否允许后缀名
bCheck = false; this.onNotExtIn();
} else if(!!this.ExtOut.length && RegExp(".(" + this.ExtOut.join("|") + ")$", "i").test(file.value)) {
//检测是否禁止后缀名
bCheck = false; this.onExtOut();
} else if(!!this.Distinct) {
Each(this.Files, function(o){ if(o.value == file.value){ bCheck = false; } })
if(!bCheck){ this.onSame(); }
}
//没有通过检测
!bCheck && this.onFail(file);
},
//删除指定file
Delete: function(file) {
//移除指定file
this.Folder.removeChild(file); this.Ini();
},
//删除全部file
Clear: function() {
//清空文件空间
Each(this.Files, Bind(this, function(o){ this.Folder.removeChild(o); })); this.Ini();
}
}
var fu = new FileUpload("uploadForm", "idFile", { ExtIn: ["gif","jpg"],
onIniFile: function(file){ file.value ? file.style.display = "none" : this.Folder.removeChild(file); },
onEmpty: function(){ alert("请选择一个文件"); },
onLimite: function(){ alert("超过上传限制"); },
onSame: function(){ alert("已经有相同文件"); },
onNotExtIn: function(){ alert("只允许上传" + this.ExtIn.join(",") + "文件"); },
onFail: function(file){ this.Folder.removeChild(file); },
onIni: function(){
//显示文件列表
var arrRows = [];
if(this.Files.length){
var oThis = this;
Each(this.Files, function(o){
var a = document.createElement("a"); a.innerHTML = "取消"; a.href = "javascript:void(0);";
a.onclick = function(){ oThis.Delete(o); return false; };
arrRows.push([o.value, a]);
});
} else { arrRows.push(["<font color='gray'>没有添加文件</font>", " "]); }
AddList(arrRows);
//设置按钮
$("idBtnupload").disabled = $("idBtndel").disabled = this.Files.length <= 0;
}
});
$("idBtnupload").onclick = function(){
//显示文件列表
var arrRows = [];
Each(fu.Files, function(o){ arrRows.push([o.value, " "]); });
AddList(arrRows);
fu.Folder.style.display = "none";
$("idProcess").style.display = "";
$("idMsg").innerHTML = "正在添加文件到您的网盘中,请稍候……<br />有可能因为网络问题,出现程序长时间无响应,请点击“<a href='?'><font color='red'>取消</font></a>”重新上传文件";
fu.Form.submit();
}
//用来添加文件列表的函数
function AddList(rows){
//根据数组来添加列表
var FileList = $("idFileList"), oFragment = document.createDocumentFragment();
//用文档碎片保存列表
Each(rows, function(cells){
var row = document.createElement("tr");
Each(cells, function(o){
var cell = document.createElement("td");
if(typeof o == "string"){ cell.innerHTML = o; }else{ cell.appendChild(o); }
row.appendChild(cell);
});
oFragment.appendChild(row);
})
//ie的table不支持innerHTML所以这样清空table
while(FileList.hasChildNodes()){ FileList.removeChild(FileList.firstChild); }
FileList.appendChild(oFragment);
}
$("idLimit").innerHTML = fu.Limit;
$("idExt").innerHTML = fu.ExtIn.join(",");
$("idBtndel").onclick = function(){ fu.Clear(); }
//在后台通过window.parent来访问主页面的函数
function Finish(msg){ alert(msg); location.href = location.href; }
</script>
</body>
</html>
file.php文件上传的php源码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="Files";//设置上传域名称
foreach($_FILES[$f_input]["error"] as $key => $error){
$up_error="no";
if ($error == UPLOAD_ERR_OK){
$f_name=$_FILES[$f_input]['name'][$key];//获取上传源文件名
$uploadfile=$uploaddir.strtolower(basename($f_name));
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
$up_error="yes";
}
if ($_FILES[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_FILES[$f_input]
['size'][$key]/1024)."Kb,大于规定的".($file_size_max/1024)."Kb,上传失败!')</script>";
$up_error="yes";
}
if (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
$up_error="yes";
}
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdHis").substr($gettime[0],2,6).$rand;
$attdir="./file/";
if(!is_dir($attdir))
{ mkdir($attdir);}
$uploadfile=$attdir.$t.".".$tmp_type;
if(($up_error!="yes") and (move_uploaded_file($_FILES[$f_input]['tmp_name']
[$key], $uploadfile))){
$_msg=$_msg.$f_name.'上传成功n';
}
else{
$_msg=$_msg.$f_name.'上传失败n';
}
}
}
echo "<script>window.parent.Finish('".$_msg."');</script>";
?>
</body>
</html>
效果图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>google分页</title>
<meta name="keywords" content="仿google php分页程序 " />
<meta name="description" content="仿google php分页程序" />
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px; }
div { height: auto; width: 800px; margin: 10px auto; line-height:20px; }
/*CSS manu style pagination*/
.manu {
PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center
}
.manu A {
BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #036cb4; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid; TEXT-DECORATION: none
}
.manu A:hover {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu A:active {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu .current {
BORDER-RIGHT: #036cb4 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #036cb4 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #036cb4 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #036cb4 1px solid; BACKGROUND-COLOR: #036cb4
}
.manu .disabled {
BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid
}
-->
</style>
</head>
<body>
<?php
require('web_page.php'); //包含分页程序
//数据库配置
$mysql_host = 'localhost'; //数据库服务器
$mysql_user = 'root'; //数据库用户名
$mysql_pass = '123456'; //数据库密码
$mysql_db = 'test'; //数据库名
//连接mysql数据库
$link = mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die ('连接MYSQL服务器出错');
mysql_select_db($mysql_db,$link) or die ('连接MYSQL数据库出错');
//分页开始
$sql_page = "select news_id,news_title from cms_news order by news_id desc";
$sql = mysql_query($sql_page);
$num = mysql_num_rows($sql); //总条数
$max = 1; //每页条数
$pagenum = ceil($num/$max); //可分页数
if(!isset($_GET['page']) or !intval($_GET['page']) or !is_numeric($_GET['page']) or $_GET['page'] > $pagenum){
$page = 1; //当页数不存在 不为十进制数 不是数字 大于可分页数 为1
}else{
$page = $_GET['page']; //当前页数
}
$min = ($page-1)*$max; //当前页从$min条开始
$sql = "{$sql_page} limit $min,$max";
echo '<div>';
if($num){
$sql = mysql_query($sql);
for(;$row = mysql_fetch_array($sql);){
echo '<li><a href="show.php?id='.$row['news_id'].'">'.$row['news_title'].'</a></li>';
}
}else{
echo '<li>暂无</li>';
}
echo '</div>';
//mysql_free_result($sql); //释放资源
?>
<div class="manu"><?php web_page(""); //调用输出分页,引用你的页面其他参数 如:web_page("&class=2&news=6") ?></div>
<?php
//分页结束
mysql_close();
?>
</body>
</html>
上面为调用方法下面为分页程序
<?php
function web_page($pageurl="", $pageselect = true){
global $page,$num,$pagenum; //当前页数 总页数 可分页数
echo "共 $num 条记录,";
$uppage = $page - 1; //上一页
$downpage = $page + 1; //下一页
$lr = 5; //显示多少个页数连接
$left = floor(($lr-1)/2); //左显示多少个页数连接
$right = floor($lr/2); //右显示多少个页数连接
//下面求开始页和结束页
if($page <= $left){ //如果当前页左不足以显示页数
$leftpage = 1;
$rightpage = (($lr<$pagenum)?$lr:$pagenum);
}elseif(($pagenum-$page) < $right){ //如果当前页右不足以显示页数
$leftpage = (($pagenum<$lr)?1:($pagenum-$lr+1));
$rightpage = $pagenum;
}else{ //左右可以显示页数
$leftpage = $page - $left;
$rightpage = $page + $right;
}
//前$lr页和后$lr页
$qianpage = (($page-$lr) < 1?1:($page-$lr));
$houpage = (($page+$lr) > $pagenum?$pagenum:($page+$lr));
//输出分页
if($page != 1){
echo "<a title="首页" href="".$_SERVER['PHP_SELF']."?$pageurl"><<</a> <a title="上一页" href="".$_SERVER['PHP_SELF']."?page=$uppage$pageurl"><</a> ";
}else{
echo "<span class='disabled'><<</span><span class='disabled'><</span> ";
}
for($pages = $leftpage; $pages <= $rightpage; $pages++){
if($pages == $page){
echo "<span class='current'>$pages</span> ";
}else{
echo "<a href="?page=$pages$pageurl">$pages</a> ";
}
}
if($page != $pagenum){
echo "<a title="下一页" href="".$_SERVER['PHP_SELF']."?page=$downpage$pageurl">></a> <a title="末页" href="".$_SERVER['PHP_SELF']."?page=$pagenum$pageurl">>></a>";
}else{
echo "<span class='disabled'>></span><span class='disabled'> >></span> ";
}
//跳转
$javapage = <<<EOM
<script language="javascript">
function web_page(targ,selObj,restore){
eval("self"+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
EOM;
echo $javapage;
if ($pageselect){
echo "跳转至 <select onchange="web_page('parent',this,0)" name="menu1">";
for($pages = 1; $pages <= $pagenum; $pages++){
$selected = ($pages == $page)?" selected="selected"":"";
echo "<option value="".$_SERVER['PHP_SELF']."?page=$pages$pageurl"$selected> $pages</option>";
}
echo "</select> 页";
}
}
?>
从中文到英语
class Google_API_translator {
public $out = "";
function translate() {
$this->out = "";
$text = urlencode("计算机");//要翻译的单词
$google_translator_url = "http://translate.google.com/translate_a/t?client=t&text=".$text."&sl=zh_CN&tl=en";
echo $google_translator_url;
$gphtml = $this->postPage(array("url" => $google_translator_url));
$this->out = $gphtml;
return $this->out;
}
function postPage($opts) {
$html = "";
if($opts["url"] != "") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $opts["url"]);
$html = curl_exec($ch);
if(curl_errno($ch)) $html = "";
curl_close ($ch);
}
return $html;
}
}
$g = new Google_API_translator();
$g->translate();
从英语到中文
class Google_API_translator {
public $out = "";
function translate() {
$this->out = "";
$text = urlencode("computer");//要翻译的单词
$google_translator_url = "http://translate.google.com/translate_a/t?client=t&text=".$text."&sl=en&tl=zh_CN";
//拼凑google翻译的api url
$gphtml = $this->postPage(array("url" => $google_translator_url));
$this->out = $gphtml;
return $this->out;
}
function postPage($opts) {
$html = "";
if($opts["url"] != "") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $opts["url"]);
$html = curl_exec($ch);
if(curl_errno($ch)) $html = "";
curl_close ($ch);
}
return $html;
}
}
$g = new Google_API_translator();
$g->translate();
很完美,返回的结果中没有任何编码问题。从google返回的中文编码完全正确。
下面一段生成html文件类是一款用php的fopen生成html 静态文件的方法好,好了费话不说多了我们来看看吧。class html
{
var $dir;
var $rootdir;
var $name;
var $dirname;
var $url;
var $time;
var $dirtype;
var $nametype;
function html($nametype='name',$dirtype='year',$rootdir='html')
{
$this->setvar($nametype,$dirtype,$rootdir);
}
function setvar($nametype='name',$dirtype='year',$rootdir='html')
{
$this->rootdir=$rootdir;
$this->dirtype=$dirtype;
$this->nametype=$nametype;
}
function createdir($dir='')
{
$this->dir=$dir?$dir:$this->dir;
if (!is_dir($this->dir))
{
$temp = explode('/',$this->dir);
$cur_dir = '';
for($i=0;$i<count($temp);$i++)
{
$cur_dir .= $temp[$i].'/';
if (!is_dir($cur_dir))
{
@mkdir($cur_dir,0777);
}
}
}
}
function getdir($dirname='',$time=0)
{
$this->time=$time?$time:$this->time;
$this->dirname=$dirname?$dirname:$this->dirname;
switch($this->dirtype)
{
case 'name':
if(empty($this->dirname))
$this->dir=$this->rootdir;
else
$this->dir=$this->rootdir.'/'.$this->dirname;
break;
case 'year':
$this->dir=$this->rootdir.'/'.date("Y",$this->time);
break;
case 'month':
$this->dir=$this->rootdir.'/'.date("Y-m",$this->time);
break;
case 'day':
$this->dir=$this->rootdir.'/'.date("Y-m-d",$this->time);
break;
}
$this->createdir();
return $this->dir;
}
function geturlname($url='')
{
$this->url=$url?$url:$this->url;
$filename=basename($this->url);
$filename=explode(".",$filename);
return $filename[0];
}
function geturlquery($url='')
{
$this->url=$url?$url:$this->url;
$durl=parse_url($this->url);
$durl=explode("&",$durl[query]);
foreach($durl as $surl)
{
$gurl=explode("=",$surl);
$eurl[]=$gurl[1];
}
return join("_",$eurl);
}
function getname($url='',$time=0,$dirname='')
{
$this->url=$url?$url:$this->url;
$this->dirname=$dirname?$dirname:$this->dirname;
$this->time=$time?$time:$this->time;
$this->getdir();
switch($this->nametype)
{
case 'name':
$filename=$this->geturlname().'.htm';
$this->name=$this->dir.'/'.$filename;
break;
case 'time':
$this->name=$this->dir.'/'.$this->time.'.htm';
break;
case 'query':
$this->name=$this->dir.'/'.$this->geturlquery().'.htm';
break;
case 'namequery':
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this->geturlquery().'.htm';
break;
case 'nametime':
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this->time.'.htm';
break;
}
return $this->name;
}
function createhtml($url='',$time=0,$dirname='',$htmlname='')
{
$this->url=$url?$url:$this->url;
$this->dirname=$dirname?$dirname:$this->dirname;
$this->time=$time?$time:$this->time;
if(empty($htmlname))
$this->getname();
else
$this->name=$dirname.'/'.$htmlname;
$content=file($this->url) or die("Failed to open the url ".$this->url." !");;
$content=join("",$content);
$fp=@fopen($this->name,"w") or die("Failed to open the file ".$this->name." !");
if(@fwrite($fp,$content))
return true;
else
return false;
fclose($fp);
}
function deletehtml($url='',$time=0,$dirname='')
{
$this->url=$url?$url:$this->url;
$this->time=$time?$time:$this->time;
$this->getname();
if(@unlink($this->name))
return true;
else
return false;
}
/**
* function::deletedir()
* 删除目录
* @param $file 目录名(不带/)
* @return
*/
function deletedir($file)
{
if(file_exists($file))
{
if(is_dir($file))
{
$handle =opendir($file);
while(false!==($filename=readdir($handle)))
{
if($filename!="."&&$filename!="..")
$this->deletedir($file."/".$filename);
}
closedir($handle);
rmdir($file);
return true;
}
else
{
unlink($file);
}
}
}
}
相关文章
- 这篇文章主要给大家介绍的是关于Lua语言新手入门的简单教程,文中通过示例代码一步步介绍的非常详细,对各位新手们的入门提供了一个很方便的教程,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。...2020-06-30
- 1、先讲讲JQuery的概念,JQuery首先是由一个 America 的叫什么 John Resig的人创建的,后来又很多的JS高手也加入了这个团队。其实 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用简单的一些代...2014-05-31
- 这篇文章主要介绍了JS创建Tag标签的方法,结合具体实例形式分析了javascript动态操作页面HTML元素实现tag标签功能的步骤与相关操作技巧,需要的朋友可以参考下...2017-06-15
深入解析WordPress中加载模板的get_template_part函数
这篇文章主要介绍了WordPress中加载模板的get_template_part函数,其中重点讲解了其函数钩子的使用,需要的朋友可以参考下...2016-01-14- mysql安装成功后有几个默认的配置模板,列表如下: my-huge.cnf : 用于高端产品服务器,包括1到2GB RAM,主要运行mysql my-innodb-heavy-4G.ini : 用于只有innodb的安装,最多有4GB RAM,支持大的查询和低流量 my-large.cnf : 用于...2015-03-15
- 1、简介Smarty是一个使用PHP写出来的模板PHP模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。简单的讲,目...2014-05-31
- 这篇文章主要介绍了C# 如何设置label(标签)控件的背景颜色为透明,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2020-12-08
matplotlib之pyplot模块坐标轴标签设置使用(xlabel()、ylabel())
这篇文章主要介绍了matplotlib之pyplot模块坐标轴标签设置使用(xlabel()、ylabel()),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23- 这篇文章主要介绍了C#删除UL LI中指定标签里文字的方法,涉及C#针对页面HTML元素进行正则匹配与替换的相关操作技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要为大家详细介绍了Ionic默认的Tabs模板使用实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-09-01
- 用灵动标签(e:loop)可以实现各种幻灯效果,本节讲解制作幻灯的基本方法。 如本站JS焦点图频道里的大部分幻灯图片效果都可以用灵动标签调用的。 ...2015-12-30
- 这篇文章主要介绍了C#线程入门教程之单线程介绍,本文讲解了什么是进程、什么是线程、什么是多线程等内容,并给出了一个单线程代码示例,需要的朋友可以参考下...2020-06-25
- 在网页中,我们可以将JavaScript代码放在html文件中任何位置,但一般放在head或body标签里面。一般来说,<script>元素放在哪里与其的功能作用是紧密相关的,通过本文我们一起学习下...2016-01-18
- 有时候我们在建站的过程当中需要调用内容页中正文的第一张图片(并不是缩略图),这样就会无从下手,但其实对不懂开发的站长是太难了,往往是会用标题图片来取代,下面分享网友们贡献出...2015-12-30
- 带上下箭头jquery垂直tab选项卡切换标签,技持左侧列表上下滚动,滚动到底部带信息提示。复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml...2015-03-15
- 这篇文章主要介绍了Springboot使用thymeleaf动态模板实现刷新,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-08-31
- 这篇文章主要介绍了PHP正则表达式过滤html标签属性的相关内容,实用性非常,感兴趣的朋友参考下吧...2016-05-06
- 最近在开发一个项目,其中有需求要求我们把一段html转换为一般文本返回,使用正则表达式是明智的选择,下面小编给介绍下C#使用正则表达式过滤html标签,需要的朋友参考下...2020-06-25
- 这篇文章主要介绍了CocosCreator入门教程之用TS制作第一个游戏,对TypeScript感兴趣的同学,一定要看一下...2021-04-16
- 这篇文章主要介绍了基于mybatis中<include>标签的作用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-20