日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
10段PHP常用功能代碼

1、使用PHP Mail函數(shù)發(fā)送Email

成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比可克達拉網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式可克達拉網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋可克達拉地區(qū)。費用合理售后完善,十載實體公司更值得信賴。

$to = "viralpatel.net@gmail.com";  
$subject = "VIRALPATEL.net";  
$body = "Body of your message here you can use HTML too. e.g. ﹤br﹥ ﹤b﹥ Bold ﹤/b﹥";  
$headers = "From: Peter\r\n";  
$headers .= "Reply-To: info@yoursite.com\r\n";  
$headers .= "Return-Path: info@yoursite.com\r\n";  
$headers .= "X-Mailer: PHP5\n";  
$headers .= 'MIME-Version: 1.0' . "\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
mail($to,$subject,$body,$headers);  
?﹥   

2、PHP中的64位編碼和解碼

function base64url_encode($plainText) {
	$base64 = base64_encode($plainText);
	$base64url = strtr($base64, '+/=', '-_,');
	return $base64url;
}

function base64url_decode($plainText) {
	$base64url = strtr($plainText, '-_,', '+/=');
	$base64 = base64_decode($base64url);
	return $base64;
} 

3、獲取遠程IP地址

function getRealIPAddr()
{
	if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
	{
		$ip=$_SERVER['HTTP_CLIENT_IP'];
	}
	elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
	{
		$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	else
	{
		$ip=$_SERVER['REMOTE_ADDR'];
	}
	return $ip;
}

4、 日期格式化

function checkDateFormat($date)
{
	//match the format of the date
	if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts))
	{
		//check weather the date is valid of not
		if(checkdate($parts[2],$parts[3],$parts[1]))
			return true;
		else
		return false;
	}
	else
		return false;
}

5、驗證Email

$email = $_POST['email'];
if(preg_match("~([a-zA-Z0-9!#$%&'*+-/=?^_`{|}~])@([a-zA-Z0-9-]).
                                 ([a-zA-Z0-9]{2,4})~",$email)) {
	echo 'This is a valid email.';
} else{
	echo 'This is an invalid email.';
} 

#p#

6、在PHP中輕松解析XML

//this is a sample xml string
$xml_string="﹤?xml version='1.0'?﹥
﹤moleculedb﹥
    ﹤molecule name='Benzine'﹥
        ﹤symbol﹥ben﹤/symbol﹥
        ﹤code﹥A﹤/code﹥
    ﹤/molecule﹥
    ﹤molecule name='Water'﹥
        ﹤symbol﹥h2o﹤/symbol﹥
        ﹤code﹥K﹤/code﹥
    ﹤/molecule﹥
﹤/moleculedb﹥";

//load the xml string using simplexml function
$xml = simplexml_load_string($xml_string);

//loop through the each node of molecule
foreach ($xml-﹥molecule as $record)
{
   //attribute are accessted by
   echo $record['name'], '  ';
   //node are accessted by -﹥ operator
   echo $record-﹥symbol, '  ';
   echo $record-﹥code, '﹤br /﹥';
}

7、數(shù)據(jù)庫連接

﹤?php
if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])) send_404();
$dbHost = "localhost";        //Location Of Database usually its localhost
$dbUser = "xxxx";            //Database User Name
$dbPass = "xxxx";            //Database Password
$dbDatabase = "xxxx";       //Database Name

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or 
                                   die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

# This function will send an imitation 404 page if the user
# types in this files filename into the address bar.
# only files connecting with in the same directory as this
# file will be able to use it as well.
function send_404()
{
    header('HTTP/1.x 404 Not Found');
    print '﹤!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"﹥'."n".
    '﹤html﹥﹤head﹥'."n".
    '﹤title﹥404 Not Found﹤/title﹥'."n".
    '﹤/head﹥﹤body﹥'."n".
    '﹤h1﹥Not Found﹤/h1﹥'."n".
    '﹤p﹥The requested URL '.
    str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']).
    ' was not found on this server.﹤/p﹥'."n".
    '﹤/body﹥﹤/html﹥'."n";
    exit;
}

# In any file you want to connect to the database,
# and in this case we will name this file db.php
# just add this line of php code (without the pound sign):
# include"db.php";
?﹥

8、創(chuàng)建和解析JSON數(shù)據(jù)

$json_data = array ('id'=﹥1,'name'=﹥"rolf",'country'=﹥'russia',
			"office"=﹥array("google","oracle"));
echo json_encode($json_data);

9、處理MySQL時間戳

$query = "select UNIX_TIMESTAMP(date_field) as mydate 
			    from mytable where 1=1";
$records = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($records))
{
	echo $row;
} 

10、解壓縮Zip文件

﹤?php
    function unzip($location,$newLocation){
        if(exec("unzip $location",$arr)){
            mkdir($newLocation);
            for($i = 1;$i﹤ count($arr);$i++){
                $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
                copy($location.'/'.$file,$newLocation.'/'.$file);
                unlink($location.'/'.$file);
            }
            return TRUE;
        }else{
            return FALSE;
        }
    }
?﹥
//Use the code as following:
﹤?php
include 'functions.php';
if(unzip('zipedfiles/test.zip','unziped/myNewZip'))
    echo 'Success!';
else
    echo 'Error';
?﹥

【編輯推薦】

  1. 20個對開發(fā)人員非常有用的Java代碼片段
  2. PHP 6預覽 新增多項特性及改進
  3. 國外十大***PHP框架排名

網(wǎng)頁名稱:10段PHP常用功能代碼
網(wǎng)站URL:http://m.5511xx.com/article/dhhjisg.html