JS模拟静态网页分页实例

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<style>
* {
font-size:10.2pt;
font-family:tahoma;
line-height:150%;
}
.divContent
{
border:1px solid red;
background-color:#FFD2D3;
width:500px;
word-break:break-all;
margin:10px 0px 10px;
padding:10px;
}
</style>
</HEAD>
<BODY>
header
<div id="divPagenation"></div>
<div id="divContent"></div>
footer
<SCRIPT LANGUAGE="JavaScript">
<!--
s="<p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:&ldquo;牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。&rdquo; </p><p>&ldquo;班上一个调皮鬼对此并不满意。他说:&ldquo;兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。&rdquo; </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:&ldquo;牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。&rdquo; </p><p>&ldquo;班上一个调皮鬼对此并不满意。他说:&ldquo;兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。&rdquo; </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:&ldquo;牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。&rdquo; </p><p>&ldquo;班上一个调皮鬼对此并不满意。他说:&ldquo;兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。&rdquo; </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:&ldquo;牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。&rdquo; </p><p>&ldquo;班上一个调皮鬼对此并不满意。他说:&ldquo;兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。&rdquo; </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:&ldquo;牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。&rdquo; </p><p>&ldquo;班上一个调皮鬼对此并不满意。他说:&ldquo;兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。&rdquo; </p>";
function DHTMLpagenation(content) { with (this)
{
// client static html file pagenation
this.content=content;
this.contentLength=content.length;
this.pageSizeCount;
this.perpageLength=100; //default perpage byte length.
this.currentPage=1;
//this.regularExp=/.+[\?\&]{1}page=(\d+)/;
this.regularExp=/\d+/;
this.divDisplayContent;
this.contentStyle=null;
this.strDisplayContent="";
this.divDisplayPagenation;
this.strDisplayPagenation="";
arguments.length==2?perpageLength=arguments[1]:'';
try {
divExecuteTime=document.createElement("DIV");
document.body.appendChild(divExecuteTime);
}
catch(e)
{
}
if(document.getElementById("divContent"))
{
divDisplayContent=document.getElementById("divContent");
}
else
{
try
{
divDisplayContent=document.createElement("DIV");
divDisplayContent.id="divContent";
document.body.appendChild(divDisplayContent);
}
catch(e)
{
return false;
}
}
if(document.getElementById("divPagenation"))
{
divDisplayPagenation=document.getElementById("divPagenation");
}
else
{
try
{
divDisplayPagenation=document.createElement("DIV");
divDisplayPagenation.id="divPagenation";
document.body.appendChild(divDisplayPagenation);
}
catch(e)
{
return false;
}
}
DHTMLpagenation.initialize();
return this;
}};
DHTMLpagenation.initialize=function() { with (this)
{
divDisplayContent.className=contentStyle!=null?contentStyle:"divContent";
if(contentLength<=perpageLength)
{
strDisplayContent=content;
divDisplayContent.innerHTML=strDisplayContent;
return null;
}
pageSizeCount=Math.ceil((contentLength/perpageLength));
DHTMLpagenation.goto(currentPage);
DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayPage=function() { with (this)
{
strDisplayPagenation="分页:";
if(currentPage&&currentPage!=1)
strDisplayPagenation+='<a href="javascript:void(0)" onclick="DHTMLpagenation.previous()">上一页</a>&nbsp;&nbsp;';
else
strDisplayPagenation+="上一页&nbsp;&nbsp;";
for(var i=1;i<=pageSizeCount;i++)
{
if(i!=currentPage)
strDisplayPagenation+='<a href="javascript:void(0)" onclick="DHTMLpagenation.goto('+i+');">'+i+'</a>&nbsp;&nbsp;';
else
strDisplayPagenation+=i+"&nbsp;&nbsp;";
}
if(currentPage&&currentPage!=pageSizeCount)
strDisplayPagenation+='<a href="javascript:void(0)" onclick="DHTMLpagenation.next()">下一页</a>&nbsp;&nbsp;';
else
strDisplayPagenation+="下一页&nbsp;&nbsp;";
strDisplayPagenation+="共 " + pageSizeCount + " 页,每页" + perpageLength + " 字符,调整字符数:<input type='text' value='"+perpageLength+"' id='ctlPerpageLength'><input type='button' value='确定' onclick='DHTMLpagenation.change(document.getElementById(\"ctlPerpageLength\").value);'>";
divDisplayPagenation.innerHTML=strDisplayPagenation;
}};
DHTMLpagenation.previous=function() { with(this)
{
DHTMLpagenation.goto(currentPage-1);
}};
DHTMLpagenation.next=function() { with(this)
{
DHTMLpagenation.goto(currentPage+1);
}};
DHTMLpagenation.goto=function(iCurrentPage) { with (this)
{
startime=new Date();
if(regularExp.test(iCurrentPage))
{
currentPage=iCurrentPage;
strDisplayContent=content.substr((currentPage-1)*perpageLength,perpageLength);
}
else
{
alert("page parameter error!");
}
DHTMLpagenation.displayPage();
DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayContent=function() { with (this)
{
divDisplayContent.innerHTML=strDisplayContent;
}};
DHTMLpagenation.change=function(iPerpageLength) { with(this)
{
if(regularExp.test(iPerpageLength))
{
DHTMLpagenation.perpageLength=iPerpageLength;
DHTMLpagenation.currentPage=1;
DHTMLpagenation.initialize();
}
else
{
alert("请输入数字");
}
}};
// method
// DHTMLpagenation(strContent,perpageLength)
DHTMLpagenation(s,100);
//-->
</SCRIPT>
</BODY>
</HTML>

PHP生成静态页类


<? /*+++
|
| 使用方法
| $shtml = new Shtml($Url,$FileBag,$FolderName,$fileid)
| $Url: 页面 URL 地址
| $FileBag: 文件夹标记 1 为:指定文件夹
| 2 为:默认文件夹(时间(年月日))
| $FolderRoot html文件存放路径
| $FolderName 指定文件夹的名称 $FileBag为2时 可以写为空("");
| $fileid 静态页面名称(后缀 默认为 .html)
|
|
|
/*++*/
class Shtml
{
var $message1="Error 1: You write class Shtml is Wrong ! The second parameter is 1 or 2 in this class!.";
var $message2="Error 2: The file write Error.";


function __construct ($Url,$FileBag,$FolderRoot,$FolderName,$fileid)
{
$this->Url = $Url;
$this->FileBag = $FileBag;
$this->FileRoot = $FolderRoot;
$this->FileName = $FolderName;
$this->fileid = $fileid;
Shtml::useFolder ();
}

/*************获取数据*******************/
public function loadcontent ($Folder)
{
ob_start();
require_once $this->Url;
Shtml::writehtml ($Folder,ob_get_contents());
ob_clean();
}

/********** 指定文件夹*****************/
public function useFolder ()
{
if($this->FileBag==1)
{
$Folder=$this->FileName;
}
else if($this->FileBag==2)
{
$Folder=date('Ymd',time());
}
else
{
exit($this->message1);
}
if(!is_dir($this->FileRoot.$Folder)){ mkdir($this->FileRoot.$Folder,0700);}

Shtml::loadcontent ($Folder);

}
/********** 生成静态页面*****************/
public function writehtml ($Folder,$cache_value)
{
$file = fopen($this->FileRoot.$Folder.'/'.$this->fileid.'.html','w+');
fwrite($file,$cache_value);
fclose($file);
}

}


$fileid=2;
$shtml = new Shtml("http://www.qq.com",1,"","cc",$fileid);


?>


PHP邮件发送类——采用邮件专递方式,无需smtp服务器

本类参考了网上关于PHP的MIME MAIL和SMTP发送协议的文章,本类可以在*NUX或WIN平台下并且无需SMTP服务器,直接通过邮件专递方式送到邮件接收方的邮件服务器中。

    需要注意的是在发送大尺寸邮件时,建议在服务器允许MAIL()发送的情况下,尽量开启'usemail'=>true,因为用PHP的SOCKE方式发送效率相对于MAIL()函数来说要低;另外要说明的是由于采用邮件专递的方式邮件没有本地暂存发送,为了可靠性和避免长时间等待的过时问题,所以在没有启用PHP的MAIL函数时,本类没有添加支持用通过分号分隔的多帐号同时发送的功能。

    本类在nease.net的Linux+php5虚拟主机空间(该空间不能使用PHP自带的MAIL函数发邮件,写此类当时就是为了在这个空间下发送邮件)及win2003+IIS6+php4.3上测试成功。

简单范例:

require("mailer.class.php");
$mailer=new mailer();
$mailer->mConfig['mailform']="xxx@21cn.com";
$isended=$mailer->mail("nobody@example.com","the subject","hello","From: webmaster@example.com");
if($isended)
{
    echo "true";
}
else
{
    echo "false";
}

类文件: mailer.class.php

<?php
/**
* Project:     Dowebs.Lib: the PHP compiling template engine
* File:        mailer.lib.php
*
* This library is opensource software;
* @link http://www.dowebs.net/
* @copyright 2004-2005 dowebs.net studio.
* @author Xie Hengduo xiejuchen@21cn.com
* @package System
* @version 1.0.0.0
*/
class mailer{
    var $mConfig=array(
        'dns'    =>"202.96.104.16",                //设置解域MX记录的域名服务器
        'mailform'    =>"yourname@yourdomain.com",//发送邮件的帐号
        'charset'    =>"utf-8",                    //HTML附件编码
        'usemail'    =>false                        //是否使用PHP中的MAIL函数
    );
    var $dns_repl_domain="";
    var $arrMX    =array();
    var $error    ="";

    var $aattach    =array();
    var $xheaders    =array();
    var $ctencoding    = "7bit";
    var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
    var $content_type='';
    
    function mailer()
    {
        
    }
    
    //兼容的mail函数
    function mail($to,$subject,$message,$additional_headers='')
    {
        if($this->mConfig['usemail'])
        {
            return mail($to,$subject,$message,$additional_headers);
        }
        else
        {
            if($this->queryMailStmp($to))
            {
                $this->error="2 收件人邮箱地址非法";
                return false;
            }
            //连接服务器
            $is_sockopen=false;
            $hostname="";
            foreach($this->arrMX as $value)
            {
                if($fp = fsockopen ($value, 25, $errno, $errstr, 60))
                {
                    $hostname=$value;
                    $is_sockopen=true;
                    break;
                }
            }
            if (!$is_sockopen){$this->error="3 联接服务器失败";return false;}

            //HELO
            fputs($fp,"HELO {$hostname}\r\n");
            $lastmessage = fgets($fp,1024);
            if(substr($lastmessage,0,3) != 220 ){$this->error="4 错误信息$lastmessage";return false;}
            //FROM:
            fputs( $fp,"MAIL FROM:<{$this->mConfig['mailform']}>"."\r\n");
            $lastmessage = fgets ($fp,1024);
            if (substr($lastmessage,0,3) != 250){$this->error="5 错误信息$lastmessage";return false;}
            //TO:
            fputs( $fp,"RCPT TO:<$to>"."\r\n");
            $lastmessage = fgets ($fp,1024);
            if (substr($lastmessage,0,3) != 250){$this->error="6 错误信息$lastmessage";return false;}
            while(true){
                $lastmessage = fgets($fp,512);
                if((substr($lastmessage,3,1) != "-")||(empty($lastmessage)))break;
            }
            //DATA
            fputs($fp,"DATA\r\n");
            $lastmessage = fgets ($fp,1024);
            if (substr($lastmessage,0,3) != 354){$this->error="7 错误信息$lastmessage";return false;}
            $message="\n".$message;
            if($additional_headers!='')
            {
                $message = $additional_headers."\r\n".$message;
            }
            //处理To头
            $head="To: $to\r\n";
            $message = $head.$message;
            //处理Subject头
            $head="Subject: $subject\r\n";
            $message = $head.$message;
            //加上结束串
            $message .= "\r\n.\r\n";
            //发送信息
            fputs($fp, $message);
            fputs($fp,"QUIT\r\n");
            fclose($fp);
            return true;
        }
    }

    //邮址初步校验
    function is_valid_email ($email = "")
    {
        return preg_match('/^[.\w-]+@([\w-]+\.)+[a-zA-Z]{2,6}$/',$email);
    }

    function queryMailStmp($mailaddr)
    {
        if($this->is_valid_email($mailaddr))
        {
            $this->mxlookup(substr(strstr($mailaddr,'@'),1));
        }
        else
        {
            return false;
        }
    }
    //取得MX记录
    function mxlookup($domain)
    {
        if(function_exists('getmxrr'))
        {
            getmxrr($domain,$this->arrMX);
        }
        else
        {
            ##########################
            $dot_pos = 0; $temp = "";
            $QNAME="";
            while($dot_pos=strpos($domain,"."))
            {
                $temp   = substr($domain,0,$dot_pos);
                $domain = substr($domain,$dot_pos+1);
                $QNAME .= chr(strlen($temp)).$temp;
            }
            $QNAME .= chr(strlen($domain)).$domain.chr(0);
            ###########################
            $dns_packet = chr(0).chr(1).chr(1).chr(0).chr(0).chr(1).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).$QNAME.chr(0).chr(15).chr(0).chr(1);
            $dns_socket = fsockopen("udp://{$this->mConfig['dns']}", 53);
            fwrite($dns_socket,$dns_packet,strlen($dns_packet));
            $this->dns_reply = fread($dns_socket,1);
            $bytes = stream_get_meta_data($dns_socket);
            $this->dns_reply .= fread($dns_socket,$bytes['unread_bytes']);
            fclose($dns_socket);
            $this->cIx=6;
            $this->Total_Accounts="";
            for($i=0;$i<2;$i++){
                $this->Total_Accounts.=ord(substr($this->dns_reply,$this->cIx,1));
                $this->cIx++;
            }
            $this->cIx+=4;
            $this->parse_data($this->dns_repl_domain);
            $this->cIx+=7;
            for($ic=1;$ic<=$this->Total_Accounts;$ic++) {
                $QTYPE = ord($this->gdi($this->cIx));
                if($QTYPE!==15){
                    print("<font color='red' size='4' face='verdana'><B>[No MX Records returned]</b></font>");
                    die();
                }
                $this->cIx+=9;
                $mxPref = ord($this->gdi($this->cIx));
                $this->parse_data($curmx);
                $this->arrMX[] =$curmx;
                $this->cIx+=3;
            }
        }
    }
    function gdi(&$cIx,$bytes=1) {
        $this->cIx++;
        return(substr($this->dns_reply, $this->cIx-1, $bytes));
    }
    function parse_data(&$retval) {
        $arName = array();
        $byte = ord($this->gdi($this->cIx));
        while($byte!==0) {
            if($byte==192) { //compressed   
                $tmpIx = $this->cIx;
                $this->cIx = ord($this->gdi($cIx));
                $tmpName = $retval;
                $this->parse_data($tmpName);
                $retval = $retval.".".$tmpName;
                $this->cIx = $tmpIx+1;
                return;
            }
            $retval="";
            $bCount = $byte;
            for($b=0;$b<$bCount;$b++) {
                $retval .= $this->gdi($this->cIx);
            }
            $arName[]=$retval;
            $byte = ord($this->gdi($this->cIx));
        }
        $retval=join(".",$arName);
    }
    
    ############################################
    # MIME MAIL CODE
    ############################################
    function From( $from="")
    {
        if($from=='')
        {
            $this->xheaders['From']=$this->mConfig['mailform'];
        }
        else
        {
            $this->xheaders['From'] = $from;
        }
    }

    function mimemail($to,$subject,$message)
    {
        $this->boundary= "--" . md5( uniqid("myboundary") );
        if( $this->mConfig['charset'] != "us-ascii" )
        {
            $this->ctencoding = "8bit";
        }
        $headers = "";
        if( $this->mConfig['charset'] != "") {
            //global $contenttype;
            $this->xheaders["Mime-Version"] = "1.0";
            $this->xheaders["Content-Type"] = "{$this->content_type}; charset={$this->mConfig['charset']}";
            $this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
        }
        $this->xheaders["X-Mailer"] = "Dowebs.net Mailer";
        if( count( $this->aattach ) > 0 )
        {
            $this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"{$this->boundary}\"";
            $fullBody="This is a multi-part message in MIME format.\n--{$this->boundary}\n";
            $fullBody.= "Content-Type: text/html; charset={$this->mConfig['charset']}\nContent-Transfer-Encoding:{$this->ctencoding}\n\n".message."\n";
            $sep= chr(13) . chr(10);
            $ata= array();
            $k=0;
            for( $i=0; $i < count( $this->aattach); $i++ ) {
                $filename = $this->aattach[$i];
                $basename = basename($filename);
                $ctype = $this->actype[$i];        // content-type
                $disposition = $this->adispo[$i];
                if(!file_exists( $filename)){$this->error="1 Class Mail, method attach : file {$filename} can't be found";return false;}
                $subhdr= "--{$this->boundary}\nContent-Type: {$ctype};\n name=\"{$basename}\";\nContent-Transfer-Encoding: base64\nContent-Disposition: {$disposition};\n filename=\"{$basename}\"\n";
                $ata[$k++] = $subhdr;
                $linesz= filesize( $filename)+1;
                $fp= fopen( $filename, 'r' );
                $ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
                fclose($fp);
            }
            $fullBody .= implode($sep, $ata);
        }
        else
        {
            $fullBody = $message;
        }
        reset($this->xheaders);
        while( list( $hdr,$value ) = each( $this->xheaders)) {
            $headers .= "$hdr: $value\n";
        }
        
        return $this->mail($to,$subject,$fullBody,$headers);
    }
    function Attach($filename,$filetype = "",$disposition = "inline")
    {
            if( $filetype == "" )
            {
                $filetype = "application/x-unknown-content-type";
            }
            $this->aattach[] = $filename;
            $this->actype[] = $filetype;
            $this->adispo[] = $disposition;
    }

    function Content_type($contenttype)
    {
        $this->content_type=$contenttype;
    }
    
    function Priority($priority)
    {
        if(!intval($priority))return false;
        if(!isset($this->priorities[$priority-1]))return false;
        $this->xheaders["X-Priority"] = $this->priorities[$priority-1];
        return true;
    }


}
?>

php自动识别浏览器语言

  1. <?php   
  2. error_reporting(E_ALL ^ E_NOTICE);   
  3. // 分析 HTTP_ACCEPT_LANGUAGE 的属性  
  4. // 这里只取第一语言设置 (其他可根据需要增强功能,这里只做简单的方法演示)  
  5.   
  6. preg_match('/^([a-z\-]+)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches);   
  7. $lang=$matches[1];   
  8. switch($lang) {   
  9.         case'zh-cn':   
  10.                  header('Location: http://cn.example.com/');   
  11.                 break;   
  12.         case'zh-tw':   
  13.                  header('Location: http://tw.example.com/');   
  14.                 break;   
  15.         case'ko':   
  16.                  header('Location: http://ko.example.com/');   
  17.                 break;   
  18.         default:   
  19.                  header('Location: http://en.example.com/');   
  20.                 break;   
  21. }   
  22. ?>  
标签: php

PHP中数组排序

排序方法                           升序                             降序                           用户自定义顺序
键排序                             ksort()                           krsort()                       uksort()
值排序不改变键值             asort()                           arsort()                       uasort()
值排序改变键值                 sort()                             rsort()                         usort()

下面是一个排序的例子:

<?php
   $color_arr = array("b" => "blue", "a" => "aliceblue", "g" => "gold", "y" => "yellow");
   ksort($color_arr);
   reset($color_arr);
   while (list($key, $val) = each($color_arr)) {
     echo "$key = $val<br>\n";
   }
?>

 

输出结果:

 

a = aliceblue
b = blue
g = gold
y = yellow

 

下面的是一个用户自定义的排序:

 

<?php
   function cmp($a, $b){
     if ($a == $b) {
       return 0;
     }
     return ($a > $b) ? -1 :1;
   }
   $a = array(4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
   uksort($a, "cmp");
   while (list($key, $val) = each($a)) {
     echo "$key = $val<br>\n";
   }
?>

 

输出结果:

 

20 = twenty
10 = ten
4 = four
3 = three

 

uksort()是用户按键排序的,我们定义了键为number类型,在cmp()函数中进行降序排列。

标签: php, 排序

15种简洁有效的网站推广方法

1、搜索引擎推广

  Google

  Yahoo

  MSN

  百度

  一搜

  3721

  搜狐

  网易

  中华网

  21世纪

  中搜

  2 、网络广告:

  banner广告

  弹出广告

  广告交换

  3 、连接交换,文字连接和图片连接以及首页醒目位置的交换

  4 、垃圾邮件。

  5 、QQ群发信息,利用群发软件发布网站信息

  6 、签名广告,发布文章,论坛发贴后面直接签上自己的网址,或者用超连接签上自己网站的名称和关键词

  7 、qq广告,在qq上作广告或者个人签名放上自己网站的信息。

  8 、msn广告,设置和网站有关的个性签名。

  9 、论坛灌水,论坛群发,在论坛或者留言板上发布自己的信息

  10 、将网站提交到专业目录。

  11 、将网站登陆到行业站点和专业目录。

  12 、文章宣传!在文章中提到网站或者以网络营销成功案例的形式介绍!中国网络营销策划第一人王通先生在文章种多次提到hao123和手机之家,让广大网民对这2个网站有了重新认识。

  13 、新闻发布会。通过开新闻发布会,让更多的记者和媒体报道自己的网站!北京招聘网在这方面的佼佼者!

  14 、路牌灯箱广告,在树立企业形象和展示自身实力的同时,对网站宣传也起到了一定的作用,郑州盘古网络在全国独树一帜。

  15 、名片宣传。