Home  >  Article  >  Backend Development  >  10 common PHP function codes (1)_PHP tutorial

10 common PHP function codes (1)_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:26:071014browse

1. Use PHP Mail function to send email

$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: Peterrn";  $headers .= "Reply-To: info@yoursite.comrn";  $headers .= "Return-Path: info@yoursite.comrn";  $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. 64-bit encoding and decoding in PHP

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. Get remote IP address

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. Date formatting

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. Verification 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446627.htmlTechArticle1. Use PHP Mail function to send Email $to = "viralpatel.net@gmail.com"; $subject = "VIRALPATEL.net"; $body = "Body of your message here you can use HTML too. e.g. ﹤br﹥ ﹤b﹥ Bo...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn