程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 10段PHP常用功能代碼(1)

10段PHP常用功能代碼(1)

編輯:關於PHP編程

1、使用PHP Mail函數發送Email

$to = "[email protected]";  $subject = "VIRALPATEL.net";  $body = "Body of your message here you can use HTML too. e.g. ﹤br﹥ ﹤b﹥ Bold ﹤/b﹥";  $headers = "From: Peterrn";  $headers .= "Reply-To: [email protected]";  $headers .= "Return-Path: [email protected]";  $headers .= "X-Mailer: PHP5n";  $headers .= 'MIME-Version: 1.0' . "n";  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";  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 dateif (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts)){//check weather the date is valid of notif(checkdate($parts[2],$parts[3],$parts[1]))return true;elsereturn false;}elsereturn 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.';} 

1

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved