php常用功能代码,10段PHP常用功能代码(1)_PHP教程

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

http://www.bkjia.com/PHPjc/446627.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446627.htmlTechArticle1、使用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﹥ Bo...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值