抑郁症健康,内容丰富有趣,生活中的好帮手!
抑郁症健康 > php常用功能代码 10段PHP常用功能代码(1)_PHP教程

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

时间:2024-08-19 23:24:49

相关推荐

1、使用PHP Mail函数发送Email$to = "@"; $subject = ""; $body = "Body of your message here you can use HTML too. e.g. ﹤br﹥ ﹤b﹥ Bold ﹤/b﹥"; $headers = "From: Peterrn"; $headers .= "Reply-To: info@rn"; $headers .= "Return-Path: info@rn"; $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

/PHPjc/446627.true/PHPjc/446627.htmlTechArticle1、使用PHP Mail函数发送Email $to = "@"; $subject = ""; $body = "Body of your message here you can use HTML too. e.g. ﹤br﹥ ﹤b﹥ Bo...

如果觉得《php常用功能代码 10段PHP常用功能代码(1)_PHP教程》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。