代码如下 | 复制代码 |
function sizecount($filesize) { //应用方法 |
$str ='13875884450';
if( preg_match("/^(((d{3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,8}$/",$str) || preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))
{
echo '验证通过!';
}
else
{
echo '输入正确电话号码或手机号码!';
}
三个函数吧:"ob_start()、ob_end_clean()、ob_get_contents()"
ob_start():是打开缓冲区的,就是要把您需要生成的静态文件的内容缓存在这里;
ob_get_contents():是读出缓冲区里的内容,下面有代码为例;
ob_end_clean():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来;
以下为引用的内容:
代码如下 | 复制代码 |
if(file_exists("./index.htm"))//看静态index.htm文件是否存在 //文件修改时间和现在时间相差?的话,直接导向htm文件,否则重新生成htm } |
//在你的开始处加入ob_start();
代码如下 | 复制代码 |
ob_start(); |
//首页内容,就是你的动态部分了
//在结尾加入ob_end_clean(),并把本页输出到一个变量中
代码如下 | 复制代码 |
$temp=ob_get_contents(); ob_end_clean(); |
//写入文件
代码如下 | 复制代码 |
$fp=fopen("./index.htm",w); fwrite($fp,$temp) or die(写文件错误); |
//echo"生成html完成!";
涉及到textarea中的换行,因为填入的内容是base64编码之后的结果(规范规定,base64编码结果中每76个字符需要加上一个回车换行,即一个" "),在ie下测试,一切ok,但是到了firefox和谷歌浏览器下,总是提示错误,细查一下,发现不同浏览器对于换行符处理不同造成的。
在ie下,换行符传入
在firefox和谷歌浏览器下,换行符只传入了
因为后台程序默认是按照处理的,所以字符串就不匹配了。
解决办法:如果发现传入的字符串只有,没有,则用正则表达式将替换成,然后再进行业务处理即可。
3.用php函数,str_replace替换函数,比如str_replace(‘ ','<br />') ,问题是替换并没有成功,一直都没有替换掉,我弄了好久甚至开始怀疑textarea中的换行符是不是,现在想想真是太动摇了,其实我经过测 分别替换 /n 后直觉告诉我自己走进了死胡同,这不是解决问题的方式,肯定有哪里存在根本性错误。突然我想到了会不会是单引号或者双引号的问题呢,于是将str_replace(‘ ','<br />') 改成str_replace(“ ”,”<br />”),灵光闪现了,替换成功
序列
含义
换行(lf 或 ascii 字符 0×0a(10))
回车(cr 或 ascii 字符 0×0d(13))
水平制表符(ht 或 ascii 字符 0×09(9))
\
反斜线
$
美元符号
”
双引号
[0-7]{1,3}
此正则表达式序列匹配一个用八进制符号表示的字符
x[0-9a-fa-f]{1,2}
此正则表达式序列匹配一个用十六进制符号表示的字符
$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.'上传成功 ';
}
else{
$_msg=$_msg.$f_name.'上传失败 ';
}
}
}
echo "<script>window.parent.finish('".$_msg."');</script>";
?>
第二款文件上传代码
<?php
$destination_path = '../../upfile/jianjulogo/';//getcwd().directory_separator;
$result = 0;
$target_path = $destination_path . basename( $_files['myfile']['name']);
if(@move_uploaded_file($_files['myfile']['tmp_name'], $target_path)) {
$result = 1;
}
echo $target_path;
sleep(1);
?>
<script language="网页特效" type="text/javascript">window.top.window.stopupload(<?php echo $result; ?>,'<?=$target_path?>');</script>