Heim  >  Artikel  >  Backend-Entwicklung  >  Sammlung gängiger PHP-Funktionen

Sammlung gängiger PHP-Funktionen

巴扎黑
巴扎黑Original
2016-11-23 15:21:181031Durchsuche

Ich habe kürzlich nach PHP gesucht und es gespeichert.
Quelle: PHP-Quellcode-Netzwerk - Open Source-Programme (Open Source)


Inhalt:
Funktion GetIP() { //Get 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; // /www.jb51.net/article/22199.htm


function DateAdd($date, $int, $unit = "d") { //Erhöhen der Zeit (Es kann auch verbessert werden, um Stunden, Minuten und Sekunden zu erhöhen und sie hinzuzufügen, wenn Sie Zeit haben)
$dateArr = explosion("-", $date); $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) { //Berechne den Wochentag, an dem das angegebene Datum ist
$dateArr = explosion("-", $date);
return date("w", mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0])); >
Detaillierte Quellenangabe:http://www.jb51.net/article/22199.htm

function check_date($date) { //Überprüfen Sie, ob das Datum ist ein gültiges Datum
$dateArr = explosion( "-", $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) { //Überprüfen Sie, ob die Zeit die zulässige Zeit ist
$timeArr = explosion(":", $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;
}
Detaillierte Quellenangabe: http://www.jb51.net/article/22199.htm


function DateDiff($date1, $date2, $unit = "") { //Zeitvergleichsfunktion, gibt die Differenz in Sekunden, Minuten, Stunden oder Tagen zwischen zwei Daten zurück
switch ($unit) {
case 's':
$dividend = 1;
Fall 'i':
Fall 'h':
Bruch
case 'd':
$dividend = 86400;
default:
$dividend = 86400;
$time1 = strtotime ($date1); 🎜>if ($time1 && $time2)
return (float)($time1 - $time2) / $dividend;
return false;
?> : http://www.jb51.net/article/22199.htm


Methode 1: header("Location: index.php"); : echo "window.location ="$PHP_SELF";"; Methode 3: echo "";
?>
Detaillierte Quellenangabe: http://www.jb51.net/article/22199.htm

PHP-Umleitung
Codecode wie folgt kopieren :
Methode 1: header(„Location: index.php“); ";
Methode 3: echo "";
?>

Zugriff erhalten Der Browser-
-Code lautet wie folgt:
function browse_infor()
{
$browser="";$browserver=""; Lynx“, „MOSAIC“, „AOL“, „Opera“, „JAVA“, „MacWeb“, „WebExplorer“, „OmniWeb“);
$Agent = $GLOBALS["HTTP_USER_AGENT"];
für ($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]; browserver); $browserver=$temp[0]; 
$browserver =preg_replace("/([d.] )/","1",$browserver); 
$browser = "Netscape Navigator"; 

if (ereg("Mozilla",$Agent) && ereg("Opera",$Agent)) 

$temp = explosion("(", $Agent); $Part=$temp[1]; 
$temp =explode(")", $Part=$temp[1]; 
$temp = explosion(" ",$browserver);$browserver=$temp[2]; 
$browserver =preg_replace("/([d.] )/","1",$browserver); 
$browserver = " $browserver"; 
$browser = "Opera"; 

if (ereg("Mozilla",$Agent) && ereg("MSIE",$Agent)) 

$temp = explosion("(", $Agent); $Part=$temp[1]; 
$temp = explosion(";",$Part); $Part=$temp[1]; 
$temp = explosion(" ",$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() ;直接返回结果 
?> 
详细出处参考:http://www.jb51.net/article/22199.htm 

获取访问者操作系统 
复制代码 代码如下: 
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() ; 
?> 

详细出处参考:http://www.jb51.net/article/22199.htm 

文件格式类 
复制代码 代码如下: 
< ? 
$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/postscript', 
'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', 
); 
?> 

详细出处参考:http://www.jb51.net/article/22199.htm 

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等文件格式了 
?> 

Detaillierte Quellenangabe: http://www.jb51.net/article/22199.htm

Zeitvergleichsproblem
Geben Sie ein einfaches Beispiel: Beispielsweise verwendet ein Forum neue Bilder, um dort veröffentlichte Beiträge zu markieren Tag einmal.
Methode 1:
Kopieren Sie den Code wie folgt:
< >$ today=time();
$theDay=date("Y-m-d H:i:s",$today-24*3600);
$newTag=$db->rows[$i][ date] >=$theDay?":"; rows[ $i][date]>=date("Y-m-d 00:00:00")?"":""; >

Kopieren Sie den Code wie folgt:
/Von der Seite und dem Browser übermittelte Variablen extrahieren, was dem Öffnen globaler Variablen in PHP.INI entspricht
@extract ($_SERVER, EXTR_SKIP);
@extract($_SESSION, EXTR_SKIP);
@extract($ _GET, EXTR_SKIP );
@extract($_ENV, EXTR_SKIP);

Kopieren Sie den Code wie folgt:
//Dateifunktion
function readfromfile($file_name) {
if (file_exists($file_name)) {
$filenum=fopen($file_name,"r"); >$file_data =fread($filenum, filesize($file_name));
fclose($filenum);
return $file_data; 🎜>? >

Kopieren Sie den Code wie folgt:
//Dateifunktion schreiben
$filenum=fopen($file_name,$method);
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,$data); ;
return $file_data;
?>

Kopieren Sie den Code wie folgt:
//Quick Page Turntopage( $url=" index.php",$info = "Die Seite leitet weiter...",$second=2){
print "nnDie Seite leitet weiter. ...</ title>n"; <br>print "<meta http-equiv="refresh" content="$second;url=$url">n"; <br>print "<style type="text/css ">n<!--n"; <br/>print "td { Font-family: "Verdana", "Arial";font-size: 12px}n"; <br/>print " A {COLOR: #000000 ; TEXT-DECORATION: none}n"; <br/>print "-->n</style>n"; <br>print "</head>n<body>n"; <br>print "< ;table width="100%" border="0" align="center">n"; <br>print " <tr>n"; ="200"> </td>n"; <br>print " </tr>n"; <br>print " <tr>n"; <br>print " <td align=" center">n" <br>print " <table width="60%" border="0" cellpadding="8" bgcolor="#AA9FFF">n"; ;n"; <br>print " <td height="30" align="center">Informationen zur Seitenumleitungsaufforderung</td>n"; <br>print " </tr>n"; <br>print " < tr>n"; <br>print " <td align="center">$info</td>n"; print " <tr> ;n"; <br>print " <td align="center">n"; <br>print " <a href="$url">Wenn Ihr Browser keine automatische Unterstützung bietet springen, bitte klicken Sie hier</a></td>n"; <br>drucken " </tr>n"; <br>drucken " </tr>n"; <br>drucken " < /table> ;</td>n"; <br>print " </tr>n"; <br>print " <tr>n"; <br>print " <td height="200"> ; < ;/td>n"; <br>print " </tr>n"; <br>print "</table>n"; <br>print "</body>n</html> "; <br>exit; <br>?> <br><br>Generieren Sie eine Zufallszeichenfolgenfunktion <br>Kopieren Sie den Code wie folgt: <br><? <br/>function random($length) { <br/>$ hash = @#@#;$chars = @#ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz@#; <br/>$max = strlen($chars) - 1; <br/>mt_srand((double)microtime() * 1000000); <br/>for($i = 0; i < ; $length; $i ) { <br/>$hash .= $chars[mt_rand(0, $max)]; <br/>return $hash; ><br/>Schneiden Sie eine Zeichenfolge einer bestimmten Länge aus (diese Funktion gilt für GB2312) <br/>Kopieren Sie den Code wie folgt: <br/><? <br/>function Wordscut($string, $length,$sss=0 ) { <br/>if(strlen($string) > $length) { <br>if($sss){ <br>$length=$length - 3; # ; <br>} <br>for($i = 0; $i < $length; $i ) { <br/>if(ord($string[$i]) > 127) { <br>$ Wordscut .= $string[$i].$string[$i 1]; <br>$i ; sonst { <br>$wordscut .= $string[$i]} <br> } <br>return $wordscut.$addstr; <br>} <br>return $string <br>} <br><br>Holen Sie sich die Client-IP-Adresse <br>Der Code lautet wie folgt: <br><? <br/>function GetIP(){ <br/>if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) <br/>$ip = getenv ("HTTP_CLIENT_IP"); <br/>else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) <br/>$ip = getenv("HTTP_X_FORWARDED_FOR"); "REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) <br/>$ip = getenv("REMOTE_ADDR" <br/>else if (isset($_SERVER[@#REMOTE_ADDR@#]) && $_SERVER[ @#REMOTE_ADDR@#] && strcasecmp($_SERVER[@#REMOTE_ADDR@#], "unknown")) <br/>$ip = $_SERVER[@#REMOTE_ADDR@#]; <br/>else <br/>$ip = "unknown"; <br/>return($ip); <br/>?> <br><br>Beurteilen Sie die E-Mail-Adresse <br>Der Code lautet wie folgt: <br><? >function checkEmail($inAddress) <br/>{ <br/>return (ereg("^([a-zA-Z0-9_-]) @([a-zA-Z0-9_-]) (.[a- zA-Z0-9_-]) ",$inAddress)); <br/>} <br/>?> <br><br>Paging (zwei Funktionen werden zusammen verwendet) <br><br>Der Code lautet wie folgt : <br><? <br/>function getpage($sql,$page_size=20) <br/>{ <br/>global $page,$totalpage,$sums; //out param <br/>$page = $_GET ["page "]; <br/>//$eachpage = $page_size; <br/>$pagesql = strstr($sql," from "); <br/>$pagesql = "select count(*) as ids ".$ facesql; <br/>$result = mysql_query($pagesql); <br/>if($rs = mysql_fetch_array($result)) $sums = $rs[0]; ); <br/>if((!$page)($page<1)) $page=1; startpos,$ page_size "; <br/>return $sql; <br/>} <br/>function showbar($string="") <br/>{ <br/>global $page,$totalpage; <br/>$out=" Total<font ".$totalpage."color=@#red@#><b>".$totalpage."</b></font>page"; <br>$linkNum =4; <br> $start = ($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1"; linkNum/ 2))<$page round($linkNum/2)) : $totalpage=$start-1; <br/>if ($ page<>1) <br>$out .= "<a href=@#?page=1&&".$string."@#title=Erste Seite>Erste Seite</a> "; >if($start>1) <br>$out.="<a href=@#?page=".$prestart."@# title=Vorherige Seite>..<<< ;/a> "; <br>for($t=$start;$t<=$end;$t ) <br/>{ <br/>$out .= ($page==$t) ? "< Schriftart [". $t."]color=@#red@#><b>[".$t."]</b></font> " : "<a $thref=@ #?page= $t&&".$string."@#>$t</a> "; <br>} <br>if($end<$totalpage) <br/>$out.="<a href=@# ?page=".$nextend."&&".$string."@# title=Nächste Seite>>>..</a>"; <br>if($page< >$totalpage) <br>$out .= " <a href=@#?page=".$totalpage."&&".$string."@# title=last page>last page</a> ;"; out; <br/>?> <br><br>Erhalten Sie die ID der neu eingefügten Daten <br>Kopieren Sie den Code wie folgt: <br>mysql_insert_id (?> <br>Der Code lautet wie folgt: <br>//Holen Sie sich die aktuelle Skript-URL <br><?function get_php_url(){ <br/>if(!empty($_server["REQUEST_URI"])){ <br/>$scriptName = $_SERVER["REQUEST_URI"]; <br/>$nowurl = $scriptName; else{ <br/>$scriptName = $_SERVER["PHP_SELF"]; <br/>if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName; ".$_SERVER["QUERY_STRING"]; <br/>} <br/>return $nowurl; <br/>} <br/>?> <br><br>Der Code lautet wie folgt: <br>//Vollständig konvertieren -width Zahlen zu halbbreiten Zahlen <br><? <br/>function GetAlabNum($fnum){ <br/>$nums = array("0","1","2","3","4 ","5", "6","7","8","9"); <br/>$fnums = "0123456789"; <br/>for($i=0;$i<=9;$ i ) $fnum = str_replace ($nums[$i],$fnums[$i],$fnum); <br/>$fnum = ereg_replace("[^0-9.]|^0{1,}", "",$fnum) ; <br/>if($fnum=="") $fnum=0; <br/>return $fnum; <br/>//HTML-Tags entfernen <br/><? <br/>function Text2Html($txt){ <br/>$txt = str_replace(" "," ",$txt); "<","<" ,$txt); 1,}/isU"," <br/>rn",$txt); <br/>return $txt; <br/>} <br/>?> <br><br>Der Code lautet wie folgt: <br> //Relativen Pfad in absoluten Pfad konvertieren <br>< ;? <br>function relative_to_absolute($content, $feed_url) { <br>preg_match('/(http|https|ftp):///', $feed_url, $protocol); <br>$server_url = preg_replace( "/(http|https|ftp|news):///", ", $feed_url = preg_replace("//.*/ ", "", $server_url); <br> if ($server_url == '') { <br>return $content; <br>} <br>if (isset($protocol[0])) { <br>$new_content = preg_replace('/href="/ /', 'href="'.$protocol[0].$server_url.'/', $content = preg_replace('/src= "//', 'src="'.$ Protocol[0].$server_url.'/', $new_content = $content; return $new_content; <br>} <br><br>Kopieren Sie den Code wie folgt: <br>//Alle Links abrufen <br><? <br/>preg_match_all('/<as href=[ "|']?([^>"' ] )["|']?s*[^>]*>([^>] ) </a>/i',$code,$ arr); <br>return array('name'=>$arr[2],'url'=>$arr[1]); } <br>?> <br><br> Kopieren Sie den Code wie folgt: <br>/Konvertieren Sie jede Zeile der HTML-Tabelle in ein CSV-Format-Array <br><?>function get_tr_array($table ) { <br/>$table = preg_replace("'<td[ ^>]*?>'si",'"',$table); <br>$table = str_replace("</td> ",'",'$table); <br>$table = str_replace("</tr>","{tr}",$table); <br>//HTML-Tags entfernen <br>$table); = preg_replace("'<[/!]*?[^< ;>]*?>'si","",$table); <br>//Leerzeichen entfernen <br>$table = preg_replace ("'([rn])[s] '","" ,$table); <br>$table = str_replace(" ","",<br>$table = str_replace(" ", "",$table); <br>$table = explosion(" ,{tr}",$table); <br>array_pop($table); > <br><br>Kopieren Sie den Code wie folgt: <br> //Konvertieren Sie jede Zeile und Spalte der HTML-Tabelle in ein Array und sammeln Sie Tabellendaten <br><? { <br/>$table = preg_replace("'<table[^> ]*?>'si","",$table); <br>$table = preg_replace("'<tr[^> ;]*?>'si","",$table); <br>$table = preg_replace("'<td[^>]*?>'si","",$table); <br>$table = str_replace("</tr>","{ tr}",$table); <br>$table = str_replace("</td>","{td}",$table ); <br>//HTML-Tags entfernen <br>$table = preg_replace( "'<[/!]*?[^<>]*?>'si","",$table); <br>//Leerzeichen entfernen <br>$table = preg_replace("' ([rn])[s] '","",$table); <br>$table = str_replace(" ","", $table); <br>$table = str_replace(" ","",$table); <br>$table = explode('{tr}', $table); <br>array_pop($table); <br>foreach ($table as $key=>$tr) { <br>$td = explode('{td}', $tr); <br>array_pop($td); <br>$td_array[] = $td; <br>} <br>return $td_array; <br>} <br>?> <br><br>复制代码 代码如下: <br>//返回字符串中的所有单词 $distinct=true 去除重复 <br><? <br/>function split_en_str($str,$distinct=true) { <br/>preg_match_all('/([a-zA-Z]+)/',$str,$match); <br/>if ($distinct == true) { <br/>$match[1] = array_unique($match[1]); <br/>} <br/>sort($match[1]); <br/>return $match[1]; <br/>} <br/>?> <br><br>复制代码 代码如下: <br>//打印出为本PHP项目做出贡献的人员的清单 <br><? <br/>string phpcredits(void) <br/>?> <br><br><br>//获得当前的脚本网址 <br>function get_php_url(){ <br>        if(!empty($_SERVER["REQUEST_URI"])){ <br>                $scriptName = $_SERVER["REQUEST_URI"]; <br>                $nowurl = $scriptName; <br>        }else{ <br>                $scriptName = $_SERVER["PHP_SELF"]; <br>                if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName; <br>                else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"]; <br>        } <br>        return $nowurl; <br><br><br><br>} <br>//把全角数字转为半角数字 <br>function GetAlabNum($fnum){ <br>        $nums = array("0","1","2","3","4","5","6","7","8","9"); <br>        $fnums = "0123456789"; <br>        for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum); <br/> $fnum = ereg_replace("[^0-9\.]|^0{1,}","",$fnum); <br/> if($fnum=="") $fnum=0; <br/> return $fnum; <br/>} <br/>//去除HTML标记 <br/>function Text2Html($txt){ <br/> $txt = str_replace(" "," ",$txt); <br/> $txt = str_replace("<","<",$txt); <br/> $txt = str_replace(">",">",$txt); <br>        $txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt); <br>        return $txt; <br>} <br><br><br>//清除HTML标记 <br>function ClearHtml($str){ <br>        $str = str_replace('<','<',$str); <br/> $str = str_replace('>','>',$str); <br>        return $str; <br>} <br>//相对路径转化成绝对路径 <br>function relative_to_absolute($content, $feed_url) { <br>    preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol); <br>    $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url); <br>    $server_url = preg_replace("/\/.*/", "", $server_url);  <br><br>    if ($server_url == '') { <br>        return $content; <br>    } <br><br><br><br>    if (isset($protocol[0])) { <br>        $new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content); <br>$new_content = preg_replace('/src="//', 'src="'.$protocol[0].$server_url.'/', $new_content} else { <br> $new_content = $); content; <br> } <br> return $new_content; <br>} //Alle Links abrufen <br>function get_all_url($code){ <br> preg_match_all('/<as href=["| ']?([^>"' ] )["|']?s*[^>]*>([^>] )</a>/i',$code,$arr) ; <br>          return array('name'=>$arr[2],'url'=>$arr[1]} <br><br><br><br><br>//Den Inhalt im angegebenen Tag abrufen <br>function get_tag_data($str, $start, $end){ <br>                                                                                               ; 🎜> $str = explosion($end, $str[1]); <br> return $str[0]; <br>} <br>//Konvertieren Sie jede Zeile der HTML-Tabelle in ein CSV-Format-Array <br>function get_tr_array($table) { <br> $table = preg_replace("'<td[^>]*?>' si",'"',$table); <br> $table = str_replace( "</td>",'",',$table); <br> $table = str_replace("</tr> ","{tr}",$table); <br> //HTML entfernen Tags <br><br><br><br><br> $table = preg_replace("'<[/!]*? [^<>]*?>'si","",$ Tabelle); ",$table); <br> $table = str_replace(" ","",$table); <br><br> $table = explosion(",{tr}",$table); <br> array_pop($table); <br>return $table); Konvertieren Sie jede Zeile der HTML-Tabelle. Konvertieren Sie jede Spalte in ein Array und sammeln Sie Tabellendaten <br>function get_td_array($table) { <br>             $table = preg_replace("'<table[^>]*?>' si","",$table ); <br> $table = preg_replace("'<tr[^>]*?>'si","",$table); <br> $table = preg_replace ("'<td[^ >]*?>'si","",$table); $table = str_replace("</tr>","{tr}",$table ); <br> $table = str_replace("</td>","{td}",$table !]*?[^< >]*?>'si","",$table); <br>                                                                                                                                            $table); <br><br><br><br><br> $table). = str_replace(" ","",$table); <br> $table = str_replace(" ","",$table ); ); <br> array_pop($table); <br> foreach ($table as $key=>$tr) { <br>                array_pop($td); <br>              )/',$str,$match); <br> if ($ unique == true) { <br>              $match[1] = array_unique($match[1]); ><br><br><br><br><br> //Dateilesefunktion <br> function PHP_Read($file_name) { <br> $fd=fopen($file_name, r); <br> while($bufline= fgets($fd, 4096)){ <br> $buf.=$bufline; <br> fclose($fd); <br> ?> 🎜><br><br><br><br><br><br>Dateischreibfunktion <br><br><br><br><br> //Dateischreibfunktion <br> function PHP_Write($ file_name,$data,$method="w") { <br> $filenum=@fopen($file_name,$method); <br> flock($ filenum,LOCK_EX); ,$data); <br> fclose($filenum); <br> return $file_data; } <br> ?> <br> // Statische Seitengenerierungsfunktion <br> function phptohtm($filefrom,$fileto,$u2u=1){ <br> if($ u2u==1){ <br> $data=PHP_Read($filefrom) ; <br> }else{ <br> $data=$filefrom; <br> PHP_Write($fileto,$data); <br> ?> ><br><br><br><br><br><br>Funktion zum Abrufen der Zustandsinformationsmenge angeben <br><br><br><br><br> //Funktion zum Abruf der Zustandsinformationsmenge angeben <br> function rec_exist($table,$where){ <br> $query="select count(*) as num from $table ".$ where; <br> $result=mysql_query($query) or die(nerror(1 )); <br> $rowcount=mysql_fetch_array($result); <br> $num=$rowcount["num"]; <br> return false; } <br> return $num; <br> } <br> ?> <br><br><br><br><br><br> Verzeichnislöschfunktion <br><br><br> // Verzeichnislöschfunktion <br> function del_DIR($directory){ <br> $mydir=dir($directory); <br> while ($file=$mydir->read()){ <br> if((is_dir ("$directory/$file")) AND ($file!=".") AND ($file!=".. ")){ <br> del_DIR("$directory/$file"); }else{ <br> if(($file!=".") AND ($file!="..")) { <br> unlink("$directory/$file"); "Verknüpfung von $directory/$file ok"; <br> } <br> } <br><br><br> $mydir->close(); <br> rmdir($directory); 🎜> //echo „rmdir $directory ok“; Erkennung der Rechtmäßigkeit des Verzeichnisnamens <br> function isen($str){ <br> $ret=""> for($i=0;$i $p=ord(substr($str,$i,1) ); <br> if(($p<48 & $p!=45 & $p!=46) | | ($p>57 & $p<65) || ($p>90 & $p<97 & $p!=95) ||. $p>122){ <br> nerror("Entspricht nicht den Spezifikationen! "); <br> } <br> $ret.=chr($p); <br> } <br> return $ret; <br> } <br> ?> <br><br><br> <br>Paging-Funktion <br><br><br>   //分页函式 <br>   function splitlist($HALT,$LRLIST,$ECHOCNT,$paper,$table,$where,$page_id,$userid){ <br>   global $splitstr,$sumcnt; <br>   if($paper=="" || $sumcnt==""){ <br>   $query = "select count(*) as num from $table $where"; <br>   $result = mysql_query($query); <br>   $row = mysql_fetch_array($result); <br>   $sumcnt=$row["num"]; <br>   if($sumcnt==0){ <br>   nerror("该版内还没有选择发布新闻 !"); <br>    } <br>   $paper=1; <br>    } <br><br><br>   $sumpaper=($sumcnt-$sumcnt%$ECHOCNT)/$ECHOCNT; <br>   if(($sumcnt%$ECHOCNT)!=0) $sumpaper =1; <br>   if($sumpaper==1 && $HALT==0) return($where); <br>   $enwhere=base64_encode(base64_encode($where)); <br>   if(($LRLIST*2 1) < $sumpaper){ <br/>   if(($paper-$LRLIST) < 2){ <br/>   $tract=1; <br/>   $sub=$LRLIST*2 1; <br/>    }else if(($paper $LRLIST) >= $sumpaper){ <br>   $tract=$sumpaper-($LRLIST*2); <br>   $sub=$sumpaper; <br>    }else{ <br>   $tract=$paper-$LRLIST; <br>   $sub=$paper $LRLIST; <br>    } <br>    }else{ <br>   $tract=1; <br>   $sub=$sumpaper; <br>    } <br>   $uppaper=$paper-1; <br>   $downpaper=$paper 1; <br>   $startcnt=($paper-1)*$ECHOCNT; <br>   $where.=" limit ${ startcnt },${ ECHOCNT }"; <br><br><br><br>   if($tract > 1) { $splitstr="【 << "; } <br/>   else $splitstr="【 << "; <br/>   for($i=$tract;$i<=$sub;$i ){ <br/>   if ($i!=$paper) $splitstr.="".$i." "; <br/>   else $splitstr.="".$i." "; <br/>    } <br/>   if ($sub!=$sumpaper) $splitstr.=">> 】"; <br>   else $splitstr.=">> 】"; <br>   return($where); <br>    } <br>   ?> <br><br><br><br>关于分页函式的使用说明  <br>      /* <br>   #### 检索分页函式 #### <br>   Int $HALT - 检索结果仅分1页时是否(1/0)显示页码条 <br>   Int $LRLIST - (页码条显示页码数-1)/2 <br>   Int $ECHOCNT - 检索时每页显示记录的数量 <br>   Int $ paper - Beispiel: $paper=$HTTP_GET_VARS[paper]; <br>   Varchar $table – Beispiel: $table="db.table"; <br>   Varchar $where - Beispiel: $where="where field='value'"; <br>  行函式后在相应的位置执行 echo $splitstr; <br>   <br>   函式调用前需获取变量 - <br>   $paper=$HTTP_GET_VARS[paper]; <br>   $sumcnt=$HTTP_GET_VARS[sumcnt]; <br>   $enwhere=$HTTP_GET_VARS[enwhere]; <br>   <br>   Return (Varchar $where) - 分页后检索语句的检索条件  Fehler); <br>   */ <br><br><br><br><br>图片文件上传函式 <br><br><br><br><br>//图片文件上传函式 <br> function upload_img($UploadFile,$UploadFile_name,$UploadFile_size,$UploadPath,$max_size=64){ <br>   <br>   //$TimeLimit=60; //设置超时限制时间 缺省时间为 30秒 设置为0时为不限时 <br>   //set_time_limit($TimeLimit); <br>   if(($UploadFile!= "none" )&&($UploadFile != "" )){ <br>   $FileName=$UploadPath.$UploadFile_name; <br>   if($UploadFile_size <1024){ <br/>   $FileSize="(string)$UploadFile_size" . „字节“; <br/>    }elseif($UploadFile_size <(1024 * $max_size)){ <br/><br/><br/><br/>   $FileSize=number_format((double)($UploadFile_size / 1024), 1) . „KB“; <br/>    }else{ <br/>nerror("Datei überschreitet Größenbeschränkung!"); <br/> } <br/> //{ <br/> //$FileSize="number_format((double)($UploadFile_size" / (1024 * 1024)), 1) . " MB"; <br/> // } <br/> if(!file_exists($FileName)){ <br/> if(copy($UploadFile,$FileName)){ <br/> return "$UploadFile_name ($FileSize)" ; <br/> }else{ <br/> nerror("Datei $UploadFile_name fehlgeschlagen!"); Existiert bereits! So ermitteln Sie die Legitimität einer IP-Adresse <br/>if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn"--- - <br/><br/>Regelmäßige Beurteilung von E-Mails <br/>eregi("^[_.0-9a-zA-Z-] @([0-9a-zA-Z][0-9a-zA-Z_- ] .) [a-zA-Z]$", $email); <br/><br/><br/><br/>Beispiel für die Überprüfung, ob die IP-Adresse und die Maske zulässig sind <br/><br/><br/><br/><br/> <br/>$ip = '192.168.0.84'; <br/>$mask = '255.255.255.0'; <br/>$ip = ip2long($ ip); <br/>$mask = ip2long($mask); <br/>$network = ip2long($network); <br/><br/>if( ($ip & $mask) == $network) echo "valid ip und maskn"; <br/>?> <br><br><br><br>---- <br><br><br><br>So legen Sie die Ausgabe des Datei-Download-Headers fest <br> <br><br><br><br><br>header("Content-type: application/x-download"); <br>header("Content-Disposition: attachment; filename=$file_download_name;"); <br>header( "Accept-Ranges: Bytes"); <br>header("Content-Length: $download_size"); <br>echo 'xxx' <br><br><br><br>Header verwenden um die FTP-Download-Methode auszugeben, Und unterstützt die Wiederaufnahme des Haltepunkts <br><br><br><br><br>header('Pragma: public'); privat'); <br>header('Cache-Control: no-cache, must-revalidate'); <br>header('Connection: close'); <br>header ("Content-Type: audio/mpeg"); <br>header("Location:ftp://download:1bk3l4s3k9s2@232.2.22.22/2222/web Technology Development Knowledge Base/cn_web.rmvb"); <br><br><br><br><br><br><br><br>Reguläre Übereinstimmung Chinesisch <br>ereg("^[".chr(0xa1)."-".chr(0xff) ."] $ ", $str); <br><br>Batch-Ersetzen von Hyperlinks im Text <br><br><br><br><br><br><?php <br/>function urlParse($ str = ''){ <br/> if ('' == $str) return $str; replace = <<<EOPHP <br/> '<a href="'.htmlentities('1').htmlentities('2').'">'.htmlentities('1').htmlentities( '2 ').'</a>' <br>EOPHP; type) = every($types)){ <br> $ret = preg_replace("|($type://)([^s]*)|ie ", $replace, $ret); <br> <br><br><br>return $ret; <br>} <br>?><br></p></div><div class="nphpQianMsg"><div class="clear"></div></div><div class="nphpQianSheng"><span>Stellungnahme:</span><div>Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn</div></div></div><div class="nphpSytBox"><span>Vorheriger Artikel:<a class="dBlack" title="PHP-Codestil" href="http://m.php.cn/de/faq/340443.html">PHP-Codestil</a></span><span>Nächster Artikel:<a class="dBlack" title="PHP-Codestil" href="http://m.php.cn/de/faq/340447.html">PHP-Codestil</a></span></div><div class="nphpSytBox2"><div class="nphpZbktTitle"><h2>In Verbindung stehende Artikel</h2><em><a href="http://m.php.cn/de/article.html" class="bBlack"><i>Mehr sehen</i><b></b></a></em><div class="clear"></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-6t+ed+2i-1n-4w" data-ad-client="ca-pub-5902227090019525" data-ad-slot="8966999616"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><ul class="nphpXgwzList"><li><b></b><a href="http://m.php.cn/de/faq/1.html" title="So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP" class="aBlack">So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/de/faq/1.html" title="So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP" class="aBlack">So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/de/faq/1.html" title="So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP" class="aBlack">So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/de/faq/1.html" title="So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP" class="aBlack">So verwenden Sie cURL zum Implementieren von Get- und Post-Anfragen in PHP</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/de/faq/2.html" title="Alle Ausdruckssymbole in regulären Ausdrücken (Zusammenfassung)" class="aBlack">Alle Ausdruckssymbole in regulären Ausdrücken (Zusammenfassung)</a><div class="clear"></div></li></ul></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="5027754603"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><div class="nphpFoot"><div class="nphpFootBg"><ul class="nphpFootMenu"><li><a href="http://m.php.cn/de/"><b class="icon1"></b><p>Heim</p></a></li><li><a href="http://m.php.cn/de/course.html"><b class="icon2"></b><p>Kurs</p></a></li><li><a href="http://m.php.cn/de/wenda.html"><b class="icon4"></b><p>Fragen und Antworten</p></a></li><li><a href="http://m.php.cn/de/login"><b class="icon5"></b><p>Mein</p></a></li><div class="clear"></div></ul></div></div><div class="nphpYouBox" style="display: none;"><div class="nphpYouBg"><div class="nphpYouTitle"><span onclick="$('.nphpYouBox').hide()"></span><a href="http://m.php.cn/de/"></a><div class="clear"></div></div><ul class="nphpYouList"><li><a href="http://m.php.cn/de/"><b class="icon1"></b><span>Heim</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/course.html"><b class="icon2"></b><span>Kurs</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/article.html"><b class="icon3"></b><span>Artikel</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/wenda.html"><b class="icon4"></b><span>Fragen und Antworten</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/dic.html"><b class="icon6"></b><span>Wörterbuch</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/course/type/99.html"><b class="icon7"></b><span>Handbuch</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/xiazai/"><b class="icon8"></b><span>Herunterladen</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/de/faq/zt" title="Thema"><b class="icon12"></b><span>Thema</span><div class="clear"></div></a></li><div class="clear"></div></ul></div></div><div class="nphpDing" style="display: none;"><div class="nphpDinglogo"><a href="http://m.php.cn/de/"></a></div><div class="nphpNavIn1"><div class="swiper-container nphpNavSwiper1"><div class="swiper-wrapper"><div class="swiper-slide"><a href="http://m.php.cn/de/" >Heim</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/article.html" class="hover">Artikel</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/wenda.html" >Fragen und Antworten</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/course.html" >Kurs</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/faq/zt" >Thema</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/xiazai" >Herunterladen</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/game" >Spiel</a></div><div class="swiper-slide"><a href="http://m.php.cn/de/dic.html" >Wörterbuch</a></div><div class="clear"></div></div></div><div class="langadivs" ><a href="javascript:;" class="bg4 bglanguage"></a><div class="langadiv" ><a onclick="javascript:setlang('zh-cn');" class="language course-right-orders chooselan " href="javascript:;"><span>简体中文</span><span>(ZH-CN)</span></a><a onclick="javascript:setlang('en');" class="language course-right-orders chooselan " href="javascript:;"><span>English</span><span>(EN)</span></a><a onclick="javascript:setlang('zh-tw');" class="language course-right-orders chooselan " href="javascript:;"><span>繁体中文</span><span>(ZH-TW)</span></a><a onclick="javascript:setlang('ja');" class="language course-right-orders chooselan " href="javascript:;"><span>日本語</span><span>(JA)</span></a><a onclick="javascript:setlang('ko');" class="language course-right-orders chooselan " href="javascript:;"><span>한국어</span><span>(KO)</span></a><a onclick="javascript:setlang('ms');" class="language course-right-orders chooselan " href="javascript:;"><span>Melayu</span><span>(MS)</span></a><a onclick="javascript:setlang('fr');" class="language course-right-orders chooselan " href="javascript:;"><span>Français</span><span>(FR)</span></a><a onclick="javascript:;" class="language course-right-orders chooselan chooselanguage" href="javascript:;"><span>Deutsch</span><span>(DE)</span></a></div></div><script> var swiper = new Swiper('.nphpNavSwiper1', { slidesPerView : 'auto', observer: true,//修改swiper自己或子元素时,自动初始化swiper observeParents: true,//修改swiper的父元素时,自动初始化swiper }); </script></div></div><!--顶部导航 end--><script>isLogin = 0;</script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script></div><script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script><link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css' type='text/css' media='all'/><script type='text/javascript' src='/static/js/viewer.min.js?1'></script><script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script><script>jQuery.fn.wait = function (func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = this.selector, //选择器 _iIntervalID; //定时器id if( this.length ){ //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function() { if(!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if( _self.length ) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $("table.syntaxhighlighter").wait(function() { $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>"); }); $(document).on("click", ".cnblogs_code_footer",function(){ $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide(); }); $('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}}); </script></body></html>