10段PHP常用功能代码(1)_PHP教程
程序员文章站
2022-05-26 20:25:26
...
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
下一篇: MySQL表设计优化与索引
推荐阅读
-
PHP V5.2新增功能之第1部分:使用新的内存管理器_PHP教程
-
php控制linux服务器常用功能 关机 重启 开新站点等_PHP教程
-
通达OA公共代码 php常用检测函数_PHP教程
-
利用单元测试在每个层上对PHP代码进行检查(1)_PHP教程
-
php中数组首字符过滤功能代码_PHP教程
-
php中的mongodb select常用操作代码示例,mongodbselect_PHP教程
-
几种常用PHP连接数据库的代码示例_PHP教程
-
PHP脚本数据库功能详解(1)_PHP教程
-
phpExcel中文帮助手册之常用功能指南,_PHP教程
-
ThinkPHP中Common/common.php文件常用函数功能分析,_PHP教程