首页 > php教程 > php手册 > 10段PHP常用功能代码(1)

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

WBOY
发布: 2016-06-13 11:03:13
原创
1151 人浏览过

1、使用PHP Mail函数发送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、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

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板