header("content-type: text/html;charset=gbk");//输出编码,避免中文乱码
?>
<html>
<head>
<title>ajax分页演示</title>
<script language="网页特效" >
var http_request=false;
function send_request(url){//初始化,指定处理函数,发送请求的函数
http_request=false;
//开始初始化xmlhttprequest对象
if(window.xmlhttprequest){//mozilla浏览器
http_request=new xmlhttprequest();
if(http_request.overridemimetype){//设置mime类别
http_request.overridemimetype("text/xml");
}
}
else if(window.activexobject){//ie浏览器
try{
http_request=new activexobject("msxml2.xmlhttp");
}catch(e){
try{
http_request=new activexobject("microsoft.xmlhttp");
}catch(e){}
}
}
if(!http_request){//异常,创建对象实例失败
window.alert("创建xmlhttp对象失败!");
return false;
}
http_request.onreadystatechange=processrequest;
//确定发送请求方式,url,及是否同步执行下段代码
http_request.open("get",url,true);
http_request.send(null);
}
//处理返回信息的函数
function processrequest(){
if(http_request.readystate==4){//判断对象状态
if(http_request.status==200){//信息已成功返回,开始处理信息
document.getelementbyid(reobj).innerhtml=http_request.responsetext;
}
else{//页面不正常
alert("您所请求的页面不正常!");
}
}
}
function dopage(obj,url){
document.getelementbyid(obj).innerhtml="<font color='green' font-size='12'>正在读取数据...</font>";
send_request(url);
reobj=obj;
}
</script>
<style>
/* css教程 document */
#result ul li{
height:20px;
width:auto;
display:block;
color:#999;
border:1px solid #999;
float:left;
list-style:none;
font-size:12px;
margin-left:5px;
line-height:20px;
vertical-align:middle;
text-align:center;
}
#result ul li a:link{
width:50px;
height:20px;
display:block;
line-height:20px;
background:#09c;
border:1px solid #fff;
color:#fff;
text-decoration:none;
}
#result ul li a:hover{
width:50px;
height:20px;
display:block;
line-height:20px;
background:#09c;
border:1px solid #fff;
color:#f60;
text-decoration:none;
}
</style>
</head>
<body>
<div id="result">
<?php
$page=isset($_get['page'])?intval($_get['page']):1; //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10; //每页显示10条数据
同时验证电话号码与手机号码正则
$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 '输入正确电话号码或手机号码!';
php substr中文乱码解决办法
1、使用mbstring扩展库的mb_substr截取就不会出现乱码了。
2、自己书写截取函数,但效率不如用mbstring扩展库来得高。
php递归删除目录所有文件
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<?php
function tree($directory)
{
$mydir=dir($directory);
echo "<ul> ";
while($file=$mydir->read()){
if((is_dir("$directory/$file")) and ($file!=".") and ($file!=".."))
{echo "<li><font color="#ff00cc"><b>$file</b></font></li> ";
tree("$directory/$file");
}
else{
$a = explode('.',$file);
if($a[1] == 'html' || $a[1] == 'htm')
{
//unlink($file);
echo "<li>$file</li> ";
}
php str_replace函数(可限制替换个数)
/mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
个函数返回一个字符串或在出现问题的所有搜索给定的数组替换值替换。
PHP实现URL静态化
再有一种就是伪静态方式,即用户和搜索引擎看到的是.html后缀的静态页面,但实际上它还是动态程序,只不过是通过某种方式进行了伪装。
这种方式也有两种实现方式:
php获取文件大小并转换gb,mb,kb代码
function sizecount($filesize) {
if($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' gb';
} elseif($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' mb';
} elseif($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . ' kb';
} else {
$filesize = $filesize . ' bytes';
}
return $filesize;
}
dedecms 列表页文章有缩略图则显示缩略图,无则不显示图片
不少用织梦http://www.phprm.com朋友想实现这个功能,有时候未必偏偏文章都会配有图片,所以就想实现有缩略图则显示缩略图,无则不显示图片。
php数据库备份还原函数
//备份还原函数
function write_file($sql,$filename) {
$re=true;
if(!@$fp=fopen("./www.phprm.com/".$filename,"w+")) {$re=false; echo "failed to open target file";}
if(!@fwrite($fp,$sql)) {$re=false; echo "failed to write file";}
if(!@fclose($fp)) {$re=false; echo "failed to close target file";}
return $re;
}
function down_file($sql,$filename){
ob_end_clean();
header("content-encoding: none");
header("content-type: ".(strpos($_server['http_user_agent'], 'msie') ? 'application/octetstream' : 'application/octet-stream'));
mysql 数据库操作类
class dbstuff {
var $querynum = 0;
var $link;
var $sqlid;
var $record;
var $dbcharset='utf-8';
var $charset='utf-8';
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0, $halt = true) {
if($pconnect) {
if(!$this->link = @mysql_pconnect($dbhost, $dbuser, $dbpw)) {
$halt && $this->halt('can not connect to mysql server');
}
} else {
if(!$this->link = @mysql_connect($dbhost, $dbuser, $dbpw, 1)) {
$halt && $this->halt('can not connect to mysql server');
}
}
ob_start()、ob_end_clean()、ob_get_contents()函数
三个函数吧:"ob_start()、ob_end_clean()、ob_get_contents()"
ob_start():是打开缓冲区的,就是要把您需要生成的静态文件的内容缓存在这里;
ob_get_contents():是读出缓冲区里的内容,下面有代码为例;
ob_end_clean():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来;
四种取得文件扩展名php代码
三种取得文件扩展名php教程代码
//方法二
php代码