收藏的PHP常用函数 推荐收藏保存

本身常用的多少个类修正自hk的PHP代码:——————————————————————————–/*功能:获得自由字符串参数:
1、(intState of Qatar$length = 32 #随便字符长度,默认为32 2、(intState of Qatar$mode = 0
#随机字符类型,0为大小写希伯来语和数字,1为数字,2为小写子木,3为大写字母,4为大小写字母,5为大写字母和数字,6为小写字母和数字再次来到:得到的字符串使用:
$code = new activeCodeObj; $str = $code-getCode($length, $mode卡塔尔;*/class
activeCodeObj{ function getCode ($length = 32, $mode = 0) { switch
($mode) { case ‘1’: $str = ‘1234567890’; break; case ‘2’: $str =
‘abcdefghijklmnopqrstuvwxyz’; break; case ‘3’: $str =
‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’; break; case ‘4’: $str =
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz’; break; case ‘5’:
$str = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890’; break; case ‘6’: $str =
‘abcdefghijklmnopqrstuvwxyz1234567890’; break; default: $str =
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890’; break;
} $result = ”; $l = strlen($str); for($i = 0;$i $length;$i ++){ $num =
rand(0, $l); $result .= $str[$num]; } return $result;
}}PHP代码:——————————————————————————–/*效率:获得顾客端消息参数:再次回到:内定的资料使用:
$code = new clientGetObj; 1、浏览器:$str = $code-getBrowse(State of Qatar;
2、IP地址:$str = $code-getIP(卡塔尔; 4、操作系统:$str =
$code-getOS(卡塔尔(قطر‎;*/class clientGetObj{ function getBrowse() { global
$_SERVER; $Agent = $_SERVER[‘HTTP_USER_AGENT’]; $browser = ”;
$browserver = ”; $Browser = array(‘Lynx’, ‘MOSAIC’, ‘AOL’, ‘Opera’,
‘JAVA’, ‘MacWeb’, ‘WebExplorer’, ‘OmniWeb’); for($i = 0; $i = 7; $i ++){
if(strpos($Agent, $Browsers[$i])){ $browser = $Browsers[$i];
$browserver = ”; } } if(ereg(‘Mozilla’, $Agent) && !ereg(‘MSIE’,
$Agent)){ $temp = explode(‘(‘, $Agent); $Part = $temp[0]; $temp =
explode(‘/’, $Part); $browserver = $temp[1]; $temp = explode(‘ ‘,
$browserver); $browserver = $temp[0]; $browserver =
preg_replace(‘/([d.]+)/’, ‘/1’, $browserver); $browserver =
$browserver; $browser = ‘Netscape Navigator’; } if(ereg(‘Mozilla’,
$Agent) && ereg(‘Opera’, $Agent)) { $temp = explode(‘(‘, $Agent); $Part
= $temp[1]; $temp = explode(‘)’, $Part); $browserver = $temp[1];
$temp = explode(‘ ‘, $browserver); $browserver = $temp[2]; $browserver
= preg_replace(‘/([d.]+)/’, ‘/1’, $browserver); $browserver =
$browserver; $browser = ‘Opera’; } if(ereg(‘Mozilla’, $Agent) &&
ereg(‘MSIE’, $Agent)){ $temp = explode(‘(‘, $Agent); $Part = $temp[1];
$temp = explode(‘;’, $Part); $Part = $temp[1]; $temp = explode(‘ ‘,
$Part); $browserver = $temp[2]; $browserver =
preg_replace(‘/([d.]+)/’,’/1′,$browserver); $browserver =
$browserver; $browser = ‘Internet Explorer’; } if($browser != ”){
$browseinfo = $browser.’ ‘.$browserver; } else { $browseinfo = false; }
return $browseinfo; } function getIP () { global $_SERVER; if
(getenv(‘HTTP_CLIENT_IP’)) { $ip = getenv(‘HTTP_CLIENT_IP’); } else
if (getenv(‘HTTP_X_FORWARDED_FOR’)) { $ip =
getenv(‘HTTP_X_FORWARDED_FOR’); } else if (getenv(‘REMOTE_ADDR’)) {
$ip = getenv(‘REMOTE_ADDR’); } else { $ip =
$_SERVER[‘REMOTE_ADDR’]; } return $ip; } function getOS () { global
$_SERVER; $agent = $_SERVER[‘HTTP_USER_AGENT’]; $os = false; if
(eregi(‘win’, $agent) && strpos($agent, ’95’)){ $os = ‘Windows 95’; }
else if (eregi(‘win 9x’, $agent) && strpos($agent, ‘4.90’)){ $os =
‘Windows ME’; } else if (eregi(‘win’, $agent) && ereg(’98’, $agent)){
$os = ‘Windows 98’; } else if (eregi(‘win’, $agent) && eregi(‘nt 5.1’,
$agent)){ $os = ‘Windows XP’; } else if (eregi(‘win’, $agent) &&
eregi(‘nt 5’, $agent)){ $os = ‘Windows 2000’; } else if (eregi(‘win’,
$agent) && eregi(‘nt’, $agent)){ $os = ‘Windows NT’; } else if
(eregi(‘win’, $agent) && ereg(’32’, $agent)){ $os = ‘Windows 32’; } else
if (eregi(‘linux’, $agent)){ $os = ‘Linux’; } else if (eregi(‘unix’,
$agent)){ $os = ‘Unix’; } else if (eregi(‘sun’, $agent) && eregi(‘os’,
$agent)){ $os = ‘SunOS’; } else if (eregi(‘ibm’, $agent) && eregi(‘os’,
$agent)){ $os = ‘IBM OS/2’; } else if (eregi(‘Mac’, $agent) &&
eregi(‘PC’, $agent)){ $os = ‘Macintosh’; } else if (eregi(‘PowerPC’,
$agent)){ $os = ‘PowerPC’; } else if (eregi(‘AIX’, $agent)){ $os =
‘AIX’; } else if (eregi(‘HPUX’, $agent)){ $os = ‘HPUX’; } else if
(eregi(‘NetBSD’, $agent)){ $os = ‘NetBSD’; } else if (eregi(‘BSD’,
$agent)){ $os = ‘BSD’; } else if (ereg(‘OSF1’, $agent)){ $os = ‘OSF1’; }
else if (ereg(‘IRIX’, $agent)){ $os = ‘IRIX’; } else if
(eregi(‘FreeBSD’, $agent)){ $os = ‘FreeBSD’; } else if
(eregi(‘teleport’, $agent)){ $os = ‘teleport’; } else if
(eregi(‘flashget’, $agent)){ $os = ‘flashget’; } else if
(eregi(‘webzip’, $agent)){ $os = ‘webzip’; } else if (eregi(‘offline’,
$agent)){ $os = ‘offline’; } else { $os = ‘Unknown’; } return $os;
}}PHP代码:——————————————————————————–class
cnStrObj{ function substrGB ($str = ”, $start = ”, $len = ”){
if($start == 0 $start == ”){ $start = 1; } if($str == ” $len == ”){
return false; } for($i = 0; $i $start + $len; $i ++){ $tmpstr =
(ord($str[$i]) = 161 && ord($str[$i]) = 247&& ord($str[$i+1]) =
161 && ord($str[$i+1]) = 254)?$str[$i].$str[++$i]:$tmpstr =
$str[$i]; if ($i = $start && $i ($start + $len)) { $tmp .=$tmpstr; } }
return $tmp; } function isGB ($str) { $strLen = strlen($str); $length =
1; for($i = 0; $i $strLen; $i ++) { $tmpstr = ord(substr($str, $i, 1));
$tmpstr2 = ord(substr($str, $i+1, 1)); if(($tmpstr = 161 $tmpstr = 247)
&& ($tmpstr2 = 161 $tmpstr2 = 247)){ $legalflag = false; } else {
$legalflag = true; } } return $legalflag;
}}PHP代码:——————————————————————————–?php/*****************************************
Filename…….: class.smtp.inc** Project……..: SMTP Class**
Version……..: 1.00b** Last Modified..: 30 September
2001***************************************/
define(‘SMTP_STATUS_NOT_CONNECTED’, 1, TRUE);
define(‘SMTP_STATUS_CONNECTED’, 2, TRUE); class smtp{ var $connection;
var $recipients; var $headers; var $timeout; var $errors; var $status;
var $body; var $from; var $host; var $port; var $helo; var $auth; var
$user; var $pass;
/***************************************
** Constructor function. Arguments: ** $params – An assoc array of
parameters: ** ** host – The hostname of the smtp server Default:
localhost ** port – The port the smtp server runs on Default: 25 **
helo – What to send as the HELO command Default: localhost **
(typically the hostname of the ** machine this script runs on) **
auth – Whether to use basic authentication Default: FALSE ** user –
Username for authentication Default: blank ** pass – Password for
authentication Default: blank ** timeout – The timeout in seconds for
the call Default: 5 ** to fsockopen()
***************************************/
function smtp($params = array()){ if(!defined(‘CRLF’)) define(‘CRLF’,
“/r/n”, TRUE); $this-timeout = 5; $this-status =
SMTP_STATUS_NOT_CONNECTED; $this-host = ‘localhost’; $this-port = 25;
$this-helo = ‘localhost’; $this-auth = FALSE; $this-user = ”;
$this-pass = ”; $this-errors = array(); foreach($params as $key =
$value){ $this-$key = $value; } }
/***************************************
** Connect function. This will, when called ** statically, create a
new smtp object, ** call the connect function (ie this function) **
and return it. When not called statically, ** it will connect to the
server and send ** the HELO command.
***************************************/
function connect($params = array()){ if(!isset($this-status)){ $obj =
new smtp($params); if($obj-connect()){ $obj-status =
SMTP_STATUS_CONNECTED; } return $obj; }else{ $this-connection =
fsockopen($this-host, $this-port, $errno, $errstr, $this-timeout);
socket_set_timeout($this-connection, 0, 250000); $greeting =
$this-get_data(); if(is_resource($this-connection)){ return $this-auth
? $this-ehlo() : $this-helo(); }else{ $this-errors[] = ‘Failed to
connect to server: ‘.$errstr; return FALSE; } } }
/***************************************
** Function which handles sending the mail. ** Arguments: **
$params – Optional assoc array of parameters. ** Can contain: **
recipients – Indexed array of recipients ** from – The from address.
(used in MAIL FROMimg src=”images/smilies/smile.gif” alt=””, ** this
will be the return path ** headers – Indexed array of headers, one
header per array entry ** body – The body of the email ** It can
also contain any of the parameters from the connect() ** function
***************************************/
function send($params = array()){ foreach($params as $key = $value){
$this-set($key, $value); } if($this-is_connected()){ // Do we auth or
not? Note the distinction between the auth variable and auth() function
if($this-auth){ if(!$this-auth()) return FALSE; }
$this-mail($this-from); if(is_array($this-recipients))
foreach($this-recipients as $value) $this-rcpt($value); else
$this-rcpt($this-recipients); if(!$this-data()) return FALSE; //
Transparency $headers = str_replace(CRLF.’.’, CRLF.’..’,
trim(implode(CRLF, $this-headers))); $body = str_replace(CRLF.’.’,
CRLF.’..’, $this-body); $body = $body[0] == ‘.’ ? ‘.’.$body : $body;
$this-send_data($headers); $this-send_data(”);
$this-send_data($body); $this-send_data(‘.’); return
(substr(trim($this-get_data()), 0, 3) === ‘250’); }else{
$this-errors[] = ‘Not connected!’; return FALSE; } }
/***************************************
** Function to implement HELO cmd
***************************************/
function helo(){ if(is_resource($this-connection) AND
$this-send_data(‘HELO ‘.$this-helo) AND substr(trim($error =
$this-get_data()), 0, 3) === ‘250’ ){ return TRUE; }else{
$this-errors[] = ‘HELO command failed, output: ‘ .
trim(substr(trim($error),3)); return FALSE; } }
/***************************************
** Function to implement EHLO cmd
***************************************/
function ehlo(){ if(is_resource($this-connection) AND
$this-send_data(‘EHLO ‘.$this-helo) AND substr(trim($error =
$this-get_data()), 0, 3) === ‘250’ ){ return TRUE; }else{
$this-errors[] = ‘EHLO command failed, output: ‘ .
trim(substr(trim($error),3)); return FALSE; } }
/***************************************
** Function to implement AUTH cmd
***************************************/
function auth(){ if(is_resource($this-connection) AND
$this-send_data(‘AUTH LOGIN’) AND substr(trim($error =
$this-get_data()), 0, 3) === ‘334’ AND
$this-send_data(base64_encode($this-user)) // Send username AND
substr(trim($error = $this-get_data()),0,3) === ‘334’ AND
$this-send_data(base64_encode($this-pass)) // Send password AND
substr(trim($error = $this-get_data()),0,3) === ‘235’ ){ return TRUE;
}else{ $this-errors[] = ‘AUTH command failed: ‘ .
trim(substr(trim($error),3)); return FALSE; } }
/***************************************
** Function that handles the MAIL FROM: cmd
***************************************/
function mail($from){ if($this-is_connected() AND
$this-send_data(‘MAIL FROM:’.$from.”) AND
substr(trim($this-get_data()), 0, 2) === ‘250’ ){ return TRUE; }else
return FALSE; }
/***************************************
** Function that handles the RCPT TO: cmd
***************************************/
function rcpt($to){ if($this-is_connected() AND $this-send_data(‘RCPT
TO:’.$to.”) AND substr(trim($error = $this-get_data()), 0, 2) === ’25’
){ return TRUE; }else{ $this-errors[] = trim(substr(trim($error), 3));
return FALSE; } }
/***************************************
** Function that sends the DATA cmd
***************************************/
function data(){ if($this-is_connected() AND $this-send_data(‘DATA’)
AND substr(trim($error = $this-get_data()), 0, 3) === ‘354’ ){ return
TRUE; }else{ $this-errors[] = trim(substr(trim($error), 3)); return
FALSE; } }
/***************************************
** Function to determine if this object ** is connected to the
server or not.
***************************************/
function is_connected(){ return (is_resource($this-connection) AND
($this-status === SMTP_STATUS_CONNECTED)); }
/***************************************
** Function to send a bit of data
***************************************/
function send_data($data){ if(is_resource($this-connection)){ return
fwrite($this-connection, $data.CRLF, strlen($data)+2); }else return
FALSE; }
/***************************************
** Function to get data.
***************************************/
function &get_data(){ $return = ”; $line = ”;
if(is_resource($this-connection)){ while(strpos($return, CRLF) ===
FALSE OR substr($line,3,1) !== ‘ ‘){ $line = fgets($this-connection,
512); $return .= $line; } return $return; }else return FALSE; }
/***************************************
** Sets a variable
***************************************/
function set($var, $valueState of Qatar{ $this-$var = $value; return TRUE; } } // End
of class?用 PHP 动态创设 Flash 动漫 (Rate:State of Qatar 小编: unknow 宣布时间:
二零零零-7-11 随笔类型: 转发 阅读次数: 1贰11遍 来自: unknow Macromedia
集团出品的 Flash
动漫软件现已经济体改为Web页面上非凡流行的表现工具,网址开采者利用它引起浏览者的兴味。可是不幸的是,仅仅使用ActionScript创设动漫受到非常的大的界定,Macromedia已经发布,计划甩掉Flash
Generator产物,转而接纳辅助Flash MX的Cold
Fusion,大家的网址将向何处去呢?以往,大家得以行使Ming
PHP库来轻便地动态成立Flash动漫,而且和大家的代码无缝集成。我们得以借助数据Curry的数码创立出种种区别作用的动漫片。Ming
动漫库最早出今后PHP4.05本子里,代替了原先版本的LibSwf模块。Ming
库采纳C编写,援救各个语言,下边先看一下什么样行使PHP来创建动漫。该库使用轻便,和
PHP
紧聚集成,不过,该库依然居于试验阶段,这段日子的版本是0.2a,在线的课程、例子、和推推搡搡手册能够让我们有益地读书,Ming里的函数协会的很有系统,方便PHP和Flash开采者查找。使用
PHP和Ming库,不但让大家的网址有富华的装点,并且能够减去开销Flash动漫的开销和复杂性的辛劳。使用Ming库有二种方法,大家得以内嵌到PHP里,也能够把它看作叁个PHP模块来运维,里面包车型客车函数匡助具有的平台,使用时也不必要实例化。假如大家把Ming库作为PHP模块来运行以来,大家必须鲜明地调用Ming库,和利用其余模块近似,然后选拔该Curry的函数。由于采用前必需先加载模块,与把Ming作为在这之中等高校函授数编写翻译的章程比较,要有一点点性子的减少。Ming库是完全免费的,大家能够到创小编的网址下载,地址是:[url][/url],该网址….php.net/ming。一旦大家准确安装和安插了Ming库,大家得以创设三个PHP对象,从PHP里调用Ming的函数,通过调用函数和性质,就足以定义大家的卡通片了。在PHP模块里有12个对象,提供了Flash的片段功力,也可以有多少个指令可以来决定发行时的参数设定。上面就看看如何接纳它来成立动漫。使用Macromedia
Flash创制SWF格式的卡通片,大家先创建一些标识,Flash有两种档次的号子:图形、动漫剪辑、按键。一旦咱们创制了这个标志,大家就足以把它们复制参加景里,每叁个正片称为二个实例,能够放任性多的实例到我们的处境里。接下来就足以定义那一个目的的行为了,也正是概念动作和平运动动轨迹,也足以定义动漫的参数,如尺寸大小和背景颜色,假如必要,能够保存成.SWF文件。利用PHP的Ming库创造Flash动漫,和Macromedia
Flash同样,必须先成立一些标识,那一个标志就是PHP对象的实例,然后定义这一个指标在动漫场景里的职位和相互关系,接着定义对象在每一帧里的动作,最终定义动漫本人。大家能够直接把SWF间接出口到浏览器,也得以保留成SWF格式的公文,以备后用。Flash的独特之处正是图形化的客户接口,利用Ming库不但能够特别简约的调节目的,何况拥有非常的扩大性和再用性。上面大家就用一个平安无事的例证来看看哪些利用Ming库:?php/*
首先创设叁个标识,并填写颜色 */$square = new SWFShape();$sqfill =
$square-addFill(0, 0, 0xff);$square-setRightFill($sqfill);
$square-movePenTo(-250,-250);$square-drawLineTo(250,-250);$square-drawLineTo(250,250);$square-drawLineTo(-250,250);$square-drawLineTo(-250,-250);
/* 在动漫剪辑里接收方面包车型大巴暗号,并累计一些脚本 */$sqclip = new
SWFSprite();$i =
$sqclip-add($square);$i-setDepth(1);$sqclip-setframes(25);$sqclip-add(new
SWFAction(“stop();”)); $sqclip-nextFrame();$sqclip-add(new
SWFAction(“play();”)); for($n=0; $n24; $n++)
{$i-rotate(-15);$sqclip-nextFrame();}/* 上面创建按键 */function
rect($r, $g, $b) {$s = new SWFShape();$s-setRightFill($s-addFill($r, $g,
$b));$s-drawLine(500,0);$s-drawLine(0,500);$s-drawLine(-500,0);$s-drawLine(0,-500);return
$s;}$b = new SWFButton();$b-addShape(rect(0xff, 0, 0), SWFBUTTON_UP |
SWFBUTTON_HIT);$b-addShape(rect(0, 0xff, 0),
SWFBUTTON_OVER);$b-addShape(rect(0, 0, 0xff), SWFBUTTON_DOWN);
$b-addAction(new SWFAction(“setTarget(‘/box’); gotoandplay(2);”),
SWFBUTTON_MOUSEDOWN);/* 上边创立动画,并累积上面包车型客车符号和开关 */$m =
new SWFMovie();$m-setDimension(4000,3000);$i =
$m-add($sqclip);$i-setDepth(3);$i-moveTo(1650, 400);$i-setName(“box”);$i
= $m-add($b);$i-setDepth(2);$i-moveTo(1400,900);/*
最后,大家把它输出到浏览器 */header(‘Content-type:
application/x-shockwave-flash’);$m-output();?

内容:
复制代码 代码如下:

新型筹划攻读php,开采众多函数必要选用,可和谐写又麻烦,于是找了下php的常用函数,从各大php系统中弄下来的,相对是选拔的php实用函数
复制代码 代码如下:
function GetIP() { //获取IP
    if ($_SERVER[“HTTP_X_FORWARDED_FOR”])
        $ip = $_SERVER[“HTTP_X_FORWARDED_FOR”];
    else if ($_SERVER[“HTTP_CLIENT_IP”])
        $ip = $_SERVER[“HTTP_CLIENT_IP”];
    else if ($_SERVER[“REMOTE_ADDR”])
        $ip = $_SERVER[“REMOTE_ADDR”];
    else if (getenv(“HTTP_X_FORWARDED_FOR”))
        $ip = getenv(“HTTP_X_FORWARDED_FOR”);
    else if (getenv(“HTTP_CLIENT_IP”))
        $ip = getenv(“HTTP_CLIENT_IP”);
    else if (getenv(“REMOTE_ADDR”))
        $ip = getenv(“REMOTE_ADDR”);
    else
        $ip = “Unknown”;
    return $ip;
}

function GetIP() { //获取IP
if ($_SERVER[“HTTP_X_FORWARDED_FOR”])
$ip = $_SERVER[“HTTP_X_FORWARDED_FOR”];
else if ($_SERVER[“HTTP_CLIENT_IP”])
$ip = $_SERVER[“HTTP_CLIENT_IP”];
else if ($_SERVER[“REMOTE_ADDR”])
$ip = $_SERVER[“REMOTE_ADDR”];
else if (getenv(“HTTP_X_FORWARDED_FOR”))
$ip = getenv(“HTTP_X_FORWARDED_FOR”);
else if (getenv(“HTTP_CLIENT_IP”))
$ip = getenv(“HTTP_CLIENT_IP”);
else if (getenv(“REMOTE_ADDR”))
$ip = getenv(“REMOTE_ADDR”);
else
$ip = “Unknown”;
return $ip;
}
?>

function DateAdd($date, $int, $unit = “d”卡塔尔国 { //时间的充实(还足以改良成时时而都得以增添,有的时候光再补上)
    $dateArr = explode(“-“, $date);
    $value[$unit] = $int;
    return date(“Y-m-d”, mktime(0,0,0, $dateArr[1] + $value[‘m’], $dateArr[2] + $value[‘d’], $dateArr[0] + $value[‘y’]));
}

复制代码 代码如下:

function GetWeekDay($date卡塔尔国 {  //总计出给出的日子是星期几
    $dateArr = explode(“-“, $date);
    return date(“w”, mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0]));
}

function DateAdd($date, $int, $unit = “d”卡塔尔 {
//时间的充实(还足以改良成时时而都得以增添,有的时候间再补上)
$dateArr = explode(“-“, $date);
$value[$unit] = $int;
return date(“Y-m-d”, mktime(0,0,0, $dateArr[1] + $value[‘m’],
$dateArr[2] + $value[‘d’], $dateArr[0] + $value[‘y’]));
}
function GetWeekDay($dateState of Qatar { //总括出给出的日子是星期几
$dateArr = explode(“-“, $date);
return date(“w”,
mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0]));
}
?>

复制代码 代码如下:
function check_date($date卡塔尔国 { //检查日期是还是不是合法日期
    $dateArr = explode(“-“, $date);
    if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr[2])) {
        return checkdate($dateArr[1],$dateArr[2],$dateArr[0]);
    }
    return false;
}
function check_time($time卡塔尔 {  //检查时间是不是合法时间
    $timeArr = explode(“:”, $time);
    if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric($timeArr[2])) {
        if (($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59))
            return true;
        else
            return false;
    }
    return false;
}

复制代码 代码如下:

function DateDiff($date1, $date2, $unit = “”卡塔尔国 { //时间相比较函数,重返八个日子相差几秒、几分钟、几钟头或几天
    switch ($unit) {
        case ‘s’:
            $dividend = 1;
            break;
        case ‘i’:
            $dividend = 60;
            break;
        case ‘h’:
            $dividend = 3600;
            break;
        case ‘d’:
            $dividend = 86400;
            break;
        default:
            $dividend = 86400;
    }
    $time1 = strtotime($date1);
    $time2 = strtotime($date2);
    if ($time1 && $time2)
        return (float)($time1 – $time2) / $dividend;
    return false;
}

function check_date($date卡塔尔国 { //检查日期是否合法日期
$dateArr = explode(“-“, $date);
if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) &&
is_numeric($dateArr[2])) {
return checkdate($dateArr[1],$dateArr[2],$dateArr[0]);
}
return false;
}
function check_time($timeState of Qatar { //检查时间是或不是合法时间
$timeArr = explode(“:”, $time);
if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) &&
is_numeric($timeArr[2])) {
if (($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1]
>= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 &&
$timeArr[2] <= 59))
return true;
else
return false;
}
return false;
}

复制代码 代码如下:
function get_innerhtml($html,$label卡塔尔(قطر‎ {   //获取一对html标识间的html字符串
    $result_arr = preg_split(“//i”,$html);
    $pattern = “//i”;
    for ($i = 0; $i         list($left, $right) = preg_split($pattern,$result_arr[$i],2);
        $result_arr[$i] = $right;
    }
    return $result_arr;
}
//例: echo get_innerhtml(“

复制代码 代码如下:
function DateDiff($date1, $date2, $unit = “”State of Qatar {
//时间比较函数,重返多个日子相差几秒、几分钟、几钟头或几天
switch ($unit) {
case ‘s’:
$dividend = 1;
break;
case ‘i’:
$dividend = 60;
break;
case ‘h’:
$dividend = 3600;
break;
case ‘d’:
$dividend = 86400;
break;
default:
$dividend = 86400;
}
$time1 = strtotime($date1);
$time2 = strtotime($date2);
if ($time1 && $time2)
return (float)($time1 – $time2) / $dividend;
return false;
}
?>

something

PHP重定向
复制代码 代码如下:

“, “td”);   //will print “something”.

方法一:header(“Location: index.php”);
方法二:echo “window.location =”$PHP_SELF”;”;
方法三:echo “

function get_input_value($input卡塔尔国 { //获取Input的HTML代码中的Value值
    $pos = stripos($input, “value=”) + 6;
    if ($pos !== false) {
        $input = substr($input, $pos);
        if (substr($input, 0, 1) == “””)
            return substr($input, 1, strpos($input, “””, 1) – 1);
        else
            return substr($input, 0, strpos($input, ” “) – 1);
    }
    return false;
}

“;
?>

function getcontentbetween($a, $b, $str卡塔尔国 { //获取字符串$str中,字符串$a与字符串$b之间的字符串
    if ($str!==”” && $a!==”” && $b!==””) {
        $start = strpos($str, $a) + strlen($a);
        return substr($str, $start, strpos($str, $b, $start + 1) – $start);
    }
    return false;
}

取得访谈者浏览器
复制代码 代码如下:

1、关于PHP重定向
复制代码 代码如下:
方法一:header(“Location: index.php”); 
方法二:echo “window.location =”$PHP_SELF”;”; 
方法三:echo “

function browse_infor()
{
$browser=””;$browserver=””;
$Browsers
=array(“Lynx”,”MOSAIC”,”AOL”,”Opera”,”JAVA”,”MacWeb”,”WebExplorer”,”OmniWeb”);
$Agent = $GLOBALS[“HTTP_USER_AGENT”];
for ($i=0; $i<=7; $i++)
{
if (strpos($Agent,$Browsers[$i]))
{
$browser = $Browsers[$i];
$browserver =””;
}
}
if (ereg(“Mozilla”,$Agent) && !ereg(“MSIE”,$Agent))
{
$temp =explode(“(“, $Agent); $Part=$temp[0];
$temp =explode(“/”, $Part); $browserver=$temp[1];
$temp =explode(” “,$browserver); $browserver=$temp[0];
$browserver =preg_replace(“/([d.]+)/”,”1″,$browserver);
$browserver = ” $browserver”;
$browser = “Netscape Navigator”;
}
if (ereg(“Mozilla”,$Agent) && ereg(“Opera”,$Agent))
{
$temp =explode(“(“, $Agent); $Part=$temp[1];
$temp =explode(“)”, $Part); $browserver=$temp[1];
$temp =explode(” “,$browserver);$browserver=$temp[2];
$browserver =preg_replace(“/([d.]+)/”,”1″,$browserver);
$browserver = ” $browserver”;
$browser = “Opera”;
}
if (ereg(“Mozilla”,$Agent) && ereg(“MSIE”,$Agent))
{
$temp = explode(“(“, $Agent); $Part=$temp[1];
$temp = explode(“;”,$Part); $Part=$temp[1];
$temp = explode(” “,$Part);$browserver=$temp[2];
$browserver =preg_replace(“/([d.]+)/”,”1″,$browserver);
$browserver = ” $browserver”;
$browser = “Internet Explorer”;
}
if ($browser!=””)
{
$browseinfo = “$browser$browserver”;
}
else
{
$browseinfo = “Unknown”;
}
return $browseinfo;
}
//调用方法$browser=browseinfo(卡塔尔国 ;直接回到结果
?>

“; 

收获访谈者操作系统
复制代码 代码如下:

2、获取访谈者浏览器
复制代码 代码如下:
function browse_infor() 

$browser=””;$browserver=””; 
$Browsers =array(“Lynx”,”MOSAIC”,”AOL”,”Opera”,”JAVA”,”MacWeb”,”WebExplorer”,”OmniWeb”); 
$Agent = $GLOBALS[“HTTP_USER_AGENT”]; 
for ($i=0; $i<=7; $i++) 

if (strpos($Agent,$Browsers[$i])) 

$browser = $Browsers[$i]; 
$browserver =””; 


if (ereg(“Mozilla”,$Agent) && !ereg(“MSIE”,$Agent)) 

$temp =explode(“(“, $Agent); $Part=$temp[0]; 
$temp =explode(“/”, $Part); $browserver=$temp[1]; 
$temp =explode(” “,$browserver); $browserver=$temp[0]; 
$browserver =preg_replace(“/([d.]+)/”,”1″,$browserver); 
$browserver = ” $browserver”; 
$browser = “Netscape Navigator”; 

if (ereg(“Mozilla”,$Agent) && ereg(“Opera”,$Agent)) 

$temp =explode(“(“, $Agent); $Part=$temp[1]; 
$temp =explode(“)”, $Part); $browserver=$temp[1]; 
$temp =explode(” “,$browserver);$browserver=$temp[2]; 
$browserver =preg_replace(“/([d.]+)/”,”1″,$browserver); 
$browserver = ” $browserver”; 
$browser = “Opera”; 

if (ereg(“Mozilla”,$Agent) && ereg(“MSIE”,$Agent)) 

$temp = explode(“(“, $Agent); $Part=$temp[1]; 
$temp = explode(“;”,$Part); $Part=$temp[1]; 
$temp = explode(” “,$Part);$browserver=$temp[2]; 
$browserver =preg_replace(“/([d.]+)/”,”1″,$browserver); 
$browserver = ” $browserver”; 
$browser = “Internet Explorer”; 

if ($browser!=””) 

$browseinfo = “$browser$browserver”; 

else 

$browseinfo = “Unknown”; 

return $browseinfo; 

//调用方法$browser=browseinfo(卡塔尔(قطر‎ ;直接再次来到结果 

function osinfo() {
$os=””;
$Agent = $GLOBALS[“HTTP_USER_AGENT”];
if (eregi(‘win’,$Agent) && strpos($Agent, ’95’)) {
$os=”Windows 95″;
}
elseif (eregi(‘win 9x’,$Agent) && strpos($Agent, ‘4.90’)) {
$os=”Windows ME”;
}
elseif (eregi(‘win’,$Agent) && ereg(’98’,$Agent)) {
$os=”Windows 98″;
}
elseif (eregi(‘win’,$Agent) && eregi(‘nt 5.0’,$Agent)) {
$os=”Windows 2000″;
}
elseif (eregi(‘win’,$Agent) && eregi(‘nt’,$Agent)) {
$os=”Windows NT”;
}
elseif (eregi(‘win’,$Agent) && eregi(‘nt 5.1’,$Agent)) {
$os=”Windows XP”;
}
elseif (eregi(‘win’,$Agent) && ereg(’32’,$Agent)) {
$os=”Windows 32″;
}
elseif (eregi(‘linux’,$Agent)) {
$os=”Linux”;
}
elseif (eregi(‘unix’,$Agent)) {
$os=”Unix”;
}
elseif (eregi(‘sun’,$Agent) && eregi(‘os’,$Agent)) {
$os=”SunOS”;
}
elseif (eregi(‘ibm’,$Agent) && eregi(‘os’,$Agent)) {
$os=”IBM OS/2″;
}
elseif (eregi(‘Mac’,$Agent) && eregi(‘PC’,$Agent)) {
$os=”Macintosh”;
}
elseif (eregi(‘PowerPC’,$Agent)) {
$os=”PowerPC”;
}
elseif (eregi(‘AIX’,$Agent)) {
$os=”AIX”;
}
elseif (eregi(‘HPUX’,$Agent)) {
$os=”HPUX”;
}
elseif (eregi(‘NetBSD’,$Agent)) {
$os=”NetBSD”;
}
elseif (eregi(‘BSD’,$Agent)) {
$os=”BSD”;
}
elseif (ereg(‘OSF1’,$Agent)) {
$os=”OSF1″;
}
elseif (ereg(‘IRIX’,$Agent)) {
$os=”IRIX”;
}
elseif (eregi(‘FreeBSD’,$Agent)) {
$os=”FreeBSD”;
}
if ($os==”) $os = “Unknown”;
return $os;
}
//调用方法$os=os_infor() ;
?>

3、获取访谈者操作系统
复制代码 代码如下:
function osinfo() { 
$os=””; 
$Agent = $GLOBALS[“HTTP_USER_AGENT”]; 
if (eregi(‘win’,$Agent) && strpos($Agent, ’95’)) { 
$os=”Windows 95″; 

elseif (eregi(‘win 9x’,$Agent) && strpos($Agent, ‘4.90’)) { 
$os=”Windows ME”; 

elseif (eregi(‘win’,$Agent) && ereg(’98’,$Agent)) { 
$os=”Windows 98″; 

elseif (eregi(‘win’,$Agent) && eregi(‘nt 5.0’,$Agent)) { 
$os=”Windows 2000″; 

elseif (eregi(‘win’,$Agent) && eregi(‘nt’,$Agent)) { 
$os=”Windows NT”; 

elseif (eregi(‘win’,$Agent) && eregi(‘nt 5.1’,$Agent)) { 
$os=”Windows XP”; 

elseif (eregi(‘win’,$Agent) && ereg(’32’,$Agent)) { 
$os=”Windows 32″; 

elseif (eregi(‘linux’,$Agent)) { 
$os=”Linux”; 

elseif (eregi(‘unix’,$Agent)) { 
$os=”Unix”; 

elseif (eregi(‘sun’,$Agent) && eregi(‘os’,$Agent)) { 
$os=”SunOS”; 

elseif (eregi(‘ibm’,$Agent) && eregi(‘os’,$Agent)) { 
$os=”IBM OS/2″; 

elseif (eregi(‘Mac’,$Agent) && eregi(‘PC’,$Agent)) { 
$os=”Macintosh”; 

elseif (eregi(‘PowerPC’,$Agent)) { 
$os=”PowerPC”; 

elseif (eregi(‘AIX’,$Agent)) { 
$os=”AIX”; 

elseif (eregi(‘HPUX’,$Agent)) { 
$os=”HPUX”; 

elseif (eregi(‘NetBSD’,$Agent)) { 
$os=”NetBSD”; 

elseif (eregi(‘BSD’,$Agent)) { 
$os=”BSD”; 

elseif (ereg(‘OSF1’,$Agent)) { 
$os=”OSF1″; 

elseif (ereg(‘IRIX’,$Agent)) { 
$os=”IRIX”; 

elseif (eregi(‘FreeBSD’,$Agent)) { 
$os=”FreeBSD”; 

if ($os==”) $os = “Unknown”; 
return $os; 

//调用方法$os=os_infor() ; 

文本格式类
复制代码 代码如下:

当前1/2页 12下一页

$mime_types = array(
‘gif’ => ‘image/gif’,
‘jpg’ => ‘image/jpeg’,
‘jpeg’ => ‘image/jpeg’,
‘jpe’ => ‘image/jpeg’,
‘bmp’ => ‘image/bmp’,
‘png’ => ‘image/png’,
‘tif’ => ‘image/tiff’,
‘tiff’ => ‘image/tiff’,
‘pict’ => ‘image/x-pict’,
‘pic’ => ‘image/x-pict’,
‘pct’ => ‘image/x-pict’,
‘tif’ => ‘image/tiff’,
‘tiff’ => ‘image/tiff’,
‘psd’ => ‘image/x-photoshop’,
‘swf’ => ‘application/x-shockwave-flash’,
‘js’ => ‘application/x-javascrīpt’,
‘pdf’ => ‘application/pdf’,
‘ps’ => ‘application/postscrīpt’,
‘eps’ => ‘application/postscrīpt’,
‘ai’ => ‘application/postscrīpt’,
‘wmf’ => ‘application/x-msmetafile’,
‘css’ => ‘text/css’,
‘htm’ => ‘text/html’,
‘html’ => ‘text/html’,
‘txt’ => ‘text/plain’,
‘xml’ => ‘text/xml’,
‘wml’ => ‘text/wml’,
‘wbmp’ => ‘image/vnd.wap.wbmp’,
‘mid’ => ‘audio/midi’,
‘wav’ => ‘audio/wav’,
‘mp3’ => ‘audio/mpeg’,
‘mp2’ => ‘audio/mpeg’,
‘avi’ => ‘video/x-msvideo’,
‘mpeg’ => ‘video/mpeg’,
‘mpg’ => ‘video/mpeg’,
‘qt’ => ‘video/quicktime’,
‘mov’ => ‘video/quicktime’,
‘lha’ => ‘application/x-lha’,
‘lzh’ => ‘application/x-lha’,
‘z’ => ‘application/x-compress’,
‘gtar’ => ‘application/x-gtar’,
‘gz’ => ‘application/x-gzip’,
‘gzip’ => ‘application/x-gzip’,
‘tgz’ => ‘application/x-gzip’,
‘tar’ => ‘application/x-tar’,
‘bz2’ => ‘application/bzip2’,
‘zip’ => ‘application/zip’,
‘arj’ => ‘application/x-arj’,
‘rar’ => ‘application/x-rar-compressed’,
‘hqx’ => ‘application/mac-binhex40’,
‘sit’ => ‘application/x-stuffit’,
‘bin’ => ‘application/x-macbinary’,
‘uu’ => ‘text/x-uuencode’,
‘uue’ => ‘text/x-uuencode’,
‘latex’=> ‘application/x-latex’,
‘ltx’ => ‘application/x-latex’,
‘tcl’ => ‘application/x-tcl’,
‘pgp’ => ‘application/pgp’,
‘asc’ => ‘application/pgp’,
‘exe’ => ‘application/x-msdownload’,
‘doc’ => ‘application/msword’,
‘rtf’ => ‘application/rtf’,
‘xls’ => ‘application/vnd.ms-excel’,
‘ppt’ => ‘application/vnd.ms-powerpoint’,
‘mdb’ => ‘application/x-msaccess’,
‘wri’ => ‘application/x-mswrite’,
);
?>

php生成excel文档
复制代码 代码如下:

header(“Content-type:application/vnd.ms-excel”);
header(“Content-Disposition:filename=test.xls”);
echo “test1t”;
echo “test2tn”;
echo “test1t”;
echo “test2tn”;
echo “test1t”;
echo “test2tn”;
echo “test1t”;
echo “test2tn”;
echo “test1t”;
echo “test2tn”;
echo “test1t”;
echo “test2tn”;
//改变相应文件头就能够输出.doc .xls等文件格式了
?>

日子相比较难点
举三个轻易易行例子表明:比方多少个论坛对当天登出的贴子用new图片标识一下。
方法一:
复制代码 代码如下:

//$db->rows[$i][date]中为数据库中datetime字段值.
$today=time();
$theDay=date(“Y-m-d H:i:s”,$today-24*3600);
$newTag=$db->rows[$i][date]>=$theDay?”图片 1“:””;
//方法二:
$newTag=$db->rows[$i][date]>=date(“Y-m-d
00:00:00″)?”图片 2“:””;
?>

复制代码 代码如下:
//提取页面和浏览器提交的变量,功效相当于使PHP.INI开了全局变量

@extract($_SERVER, EXTR_SKIP);
@extract($_SESSION, EXTR_SKIP);
@extract($_POST, EXTR_SKIP);
@extract($_FILES, EXTR_SKIP);
@extract($_GET, EXTR_SKIP);
@extract($_ENV, EXTR_SKIP);
?>

复制代码 代码如下:
//读取文件函数

function readfromfile($file_name) {
if (file_exists($file_name)) {
$filenum=fopen($file_name,”r”);
flock($filenum,LOCK_EX);
$file_data=fread($filenum, filesize($file_name));
rewind($filenum);
fclose($filenum);
return $file_data;
}
}
?>

复制代码 代码如下:
//写入文件函数

function writetofile($file_name,$data,$method=”w”) {
$filenum=fopen($file_name,$method);
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,$data);
fclose($filenum);
return $file_data;
}
?>

复制代码 代码如下:
//页面一点也不慢转化

function turntopage($url=”index.php”,$info =
“页面转向中…”,$second=2卡塔尔{
print “n

n

页面转向中….

n”;
print “

n”;
print “

n”;
print “nn”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

页面转向提醒消息

n”;
print “

n”;
print “

n”;
print “

$info

n”;
print “

n”;
print “

n”;
print “

n”;
print ”
一旦你的浏览器不帮忙活动跳转,请按这里

n”;
print “

n”;
print ” n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “

n”;
print “n”;
exit;
?>

发出随机字符串函数
复制代码 代码如下:

function random($length) {
$hash = @#@#;
$chars =
@#ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz@#;
$max = strlen($chars) – 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
?>

截取一定长度的字符串(该函数对GB2312使用有效)
复制代码 代码如下:

function Wordscut($string, $length ,$sss=0) {
if(strlen($string) > $length) {
if($sss){
$length=$length – 3;
$addstr=@# …@#;
}
for($i = 0; $i < $length; $i++) {
if(ord($string[$i]) > 127) {
$wordscut .= $string[$i].$string[$i + 1];
$i++;
} else {
$wordscut .= $string[$i];
}
}
return $wordscut.$addstr;
}
return $string;
}
?>

得到顾客端IP地址
复制代码 代码如下:

function GetIP(){
if (getenv(“HTTP_CLIENT_IP”) && strcasecmp(getenv(“HTTP_CLIENT_IP”),
“unknown”))
$ip = getenv(“HTTP_CLIENT_IP”);
else if (getenv(“HTTP_X_FORWARDED_FOR”) &&
strcasecmp(getenv(“HTTP_X_FORWARDED_FOR”), “unknown”))
$ip = getenv(“HTTP_X_FORWARDED_FOR”);
else if (getenv(“REMOTE_ADDR”) && strcasecmp(getenv(“REMOTE_ADDR”),
“unknown”))
$ip = getenv(“REMOTE_ADDR”);
else if (isset($_SERVER[@#REMOTE_ADDR@#]) &&
$_SERVER[@#REMOTE_ADDR@#] &&
strcasecmp($_SERVER[@#REMOTE_ADDR@#], “unknown”))
$ip = $_SERVER[@#REMOTE_ADDR@#];
else
$ip = “unknown”;
return($ip);
}
?>

决断邮箱地址
复制代码 代码如下:

function checkEmail($inAddress)
{
return
(ereg(“^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+”,$inAddress));
}
?>

分页(多少个函数协作使用)
复制代码 代码如下:

function getpage($sql,$page_size=20)
{
global $page,$totalpage,$sums; //out param
$page = $_GET[“page”];
//$eachpage = $page_size;
$pagesql = strstr($sql,” from “);
$pagesql = “select count(*) as ids “.$pagesql;
$result = mysql_query($pagesql);
if($rs = mysql_fetch_array($result)) $sums = $rs[0];
$totalpage = ceil($sums/$page_size);
if((!$page)($page<1)) $page=1;
$startpos = ($page-1)*$page_size;
$sql .=” limit $startpos,$page_size “;
return $sql;
}
function showbar($string=””)
{
global $page,$totalpage;
$out=”共“.$totalpage.”页 “;
$linkNum =4;
$start = ($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) :
“1”;
$end = ($page+round($linkNum/2))$prestart=$start-1;
$nextend=$end+1;
if($page<>1)
$out .=
“第一页
“;
if($start>1)
$out.=”..<<
“;
for($t=$start;$t<=$end;$t++)
{
$out .= ($page==$t) ? “[“.$t.”] ” : “$t “;
}
if($end$out.=”>>..”;
if($page<>$totalpage)
$out .= ”
最后页”;
return $out;
}
?>

得到新插入数据的ID
复制代码 代码如下:

mysql_insert_id();
?>

复制代码 代码如下:
//得到当前的本子网站

function get_php_url(){
if(!empty($_server[“REQUEST_URI”])){
$scriptName = $_SERVER[“REQUEST_URI”];
$nowurl = $scriptName;
}else{
$scriptName = $_SERVER[“PHP_SELF”];
if(empty($_SERVER[“QUERY_STRING”])) $nowurl = $scriptName;
else $nowurl = $scriptName.”?”.$_SERVER[“QUERY_STRING”];
}
return $nowurl;
}
?>

复制代码 代码如下:
//把全角数字转为半角数字

function GetAlabNum($fnum){
$nums = array(“0”,”1”,”2”,”3”,”4”,”5”,”6”,”7”,”8”,”9”);
$fnums = “0123456789”;
for($i=0;$i<=9;$i++) $fnum =
str_replace($nums[$i],$fnums[$i],$fnum);
$fnum = ereg_replace(“[^0-9.]|^0{1,}”,””,$fnum);
if($fnum==””) $fnum=0;
return $fnum;
}
?>

复制代码 代码如下:
//去除HTML标记

function Text2Html($txt){
$txt = str_replace(” “,” ”,$txt);
$txt = str_replace(“$txt = str_replace(“>”,”>”,$txt);
$txt = preg_replace(“/[rn]{1,}/isU”,”
rn”,$txt);
return $txt;
}
?>

复制代码 代码如下:
//相对路线转产生相对路线

function relative_to_absolute($content, $feed_url) {
preg_match(‘/(http|https|ftp):///’, $feed_url, $protocol);
$server_url = preg_replace(“/(http|https|ftp|news):///”, “”,
$feed_url);
$server_url = preg_replace(“//.*/”, “”, $server_url);
if ($server_url == ”) {
return $content;
}
if (isset($protocol[0])) {
$new_content = preg_replace(‘/href=”//’,
‘href=”‘.$protocol[0].$server_url.’/’, $content);
$new_content = preg_replace(‘/src=”//’,
‘src=”‘.$protocol[0].$server_url.’/’, $new_content);
} else {
$new_content = $content;
}
return $new_content;
}
?>

复制代码 代码如下:
//得到富有链接

function get_all_url($code){
preg_match_all(‘/”‘
]+)[“|’]?s*[^>]*>([^>]+)/i’,$code,$arr);
return array(‘name’=>$arr[2],’url’=>$arr[1]);
}
?>

复制代码 代码如下:
//HTML表格的每行转为CSV格式数组

function get_tr_array($table) {
$table = preg_replace(“‘

]*?>’si”,'”‘,$table);
$table = str_replace(“

“,'”,’,$table);
$table = str_replace(“”,”{tr}”,$table);
//去掉 HTML 标记
$table = preg_replace(“‘]*?>’si”,””,$table);
//去掉空白字符
$table = preg_replace(“‘([rn])[s]+'”,””,$table);
$table = str_replace(” “,””,$table);
$table = str_replace(” “,””,$table);
$table = explode(“,{tr}”,$table);
array_pop($table);
return $table;
}
?>

复制代码 代码如下:
//将HTML表格的每行每列转为数组,搜集表格数据

function get_td_array($table) {
$table = preg_replace(“‘

]*?>’si”,””,$table);
$table = preg_replace(“‘

]*?>’si”,””,$table);
$table = preg_replace(“‘

]*?>’si”,””,$table);
$table = str_replace(“

“,”{tr}”,$table);
$table = str_replace(“”,”{td}”,$table);
//去掉 HTML 标记
$table = preg_replace(“‘]*?>’si”,””,$table);
//去掉空白字符
$table = preg_replace(“‘([rn])[s]+'”,””,$table);
$table = str_replace(” “,””,$table);
$table = str_replace(” “,””,$table);
$table = explode(‘{tr}’, $table);
array_pop($table);
foreach ($table as $key=>$tr) {
$td = explode(‘{td}’, $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}
?>

复制代码 代码如下:
//重返字符串中的全数单词 $distinct=true 去除重复

function split_en_str($str,$distinct=true) {
preg_match_all(‘/([a-zA-Z]+)/’,$str,$match);
if ($distinct == true) {
$match[1] = array_unique($match[1]);
}
sort($match[1]);
return $match[1];
}
?>

复制代码 代码如下:
//打字与印刷出为本PHP项目做出贡献的人士的清单

string phpcredits(void)
?>

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图