比如我写好的POST提交例子,验证邮箱和值是否未空?
<code>include("check.php"); $check = new VerifyAction(); if(?){ echo '提交成功!'; }else{ echo '填写不对 重填写'; } <form action="index.php" method="post"> <input type="text" name="name"><br> <input type="text" name="email"><br> <input type="submit"> </form> </code>
验证类 check.php
<code><?php /** * 验证类 * * @lastmodify 2014-5-16 * @author jy625 */ class VerifyAction{ /** * 是否为空值 */ public static function isEmpty($str){ $str = trim($str); return !empty($str) ? true : false; } /** * 数字验证 * param:$flag : int是否是整数,float是否是浮点型 */ public static function isNum($str,$flag = 'float'){ if(!self::isEmpty($str)) return false; if(strtolower($flag) == 'int'){ return ((string)(int)$str === (string)$str) ? true : false; }else{ return ((string)(float)$str === (string)$str) ? true : false; } } /** * 名称匹配,如用户名,目录名等 * @param:string $str 要匹配的字符串 * @param:$chinese 是否支持中文,默认支持,如果是匹配文件名,建议关闭此项(false) * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isName($str,$chinese = true,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; if($chinese){ $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-]+$/" : "/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/u"; }else{ $match = '/^[A-za-z0-9_-]+$/'; } return preg_match($match,$str) ? true : false; } /** * 邮箱验证 */ public static function isEmail($str){ if(!self::isEmpty($str)) return false; return preg_match("/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i",$str) ? true : false; } //手机号码验证 public static function isMobile($str){ $exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/"; if(preg_match($exp,$str)){ return true; }else{ return false; } } /** * URL验证,纯网址格式,不支持IP验证 */ public static function isUrl($str){ if(!self::isEmpty($str)) return false; return preg_match('#(http|https|ftp|ftps)://([w-]+.)+[w-]+(/[w-./?%&=]*)?#i',$str) ? true : false; } /** * 验证中文 * @param:string $str 要匹配的字符串 * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isChinese($str,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."]+$/" : "/^[x{4e00}-x{9fa5}]+$/u"; return preg_match($match,$str) ? true : false; } /** * UTF-8验证 */ public static function isUtf8($str){ if(!self::isEmpty($str)) return false; return (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true) ? true : false; } /** * 验证长度 * @param: string $str * @param: int $type(方式,默认min <= $str <= max) * @param: int $min,最小值;$max,最大值; * @param: string $charset 字符 */ public static function length($str,$type=3,$min=0,$max=0,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $len = mb_strlen($str,$charset); switch($type){ case 1: //只匹配最小值 return ($len >= $min) ? true : false; break; case 2: //只匹配最大值 return ($max >= $len) ? true : false; break; default: //min = 1000 && $timeArr[0] = 0 && $dateArr[1] = 0 && $dateArr[2] = 0 && $timeArr[0] = 0 && $timeArr[1] = 0 && $timeArr[2] </code>
回复内容:
比如我写好的POST提交例子,验证邮箱和值是否未空?
<code>include("check.php"); $check = new VerifyAction(); if(?){ echo '提交成功!'; }else{ echo '填写不对 重填写'; } <form action="index.php" method="post"> <input type="text" name="name"><br> <input type="text" name="email"><br> <input type="submit"> </form> </code>
验证类 check.php
<code><?php /** * 验证类 * * @lastmodify 2014-5-16 * @author jy625 */ class VerifyAction{ /** * 是否为空值 */ public static function isEmpty($str){ $str = trim($str); return !empty($str) ? true : false; } /** * 数字验证 * param:$flag : int是否是整数,float是否是浮点型 */ public static function isNum($str,$flag = 'float'){ if(!self::isEmpty($str)) return false; if(strtolower($flag) == 'int'){ return ((string)(int)$str === (string)$str) ? true : false; }else{ return ((string)(float)$str === (string)$str) ? true : false; } } /** * 名称匹配,如用户名,目录名等 * @param:string $str 要匹配的字符串 * @param:$chinese 是否支持中文,默认支持,如果是匹配文件名,建议关闭此项(false) * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isName($str,$chinese = true,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; if($chinese){ $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-]+$/" : "/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/u"; }else{ $match = '/^[A-za-z0-9_-]+$/'; } return preg_match($match,$str) ? true : false; } /** * 邮箱验证 */ public static function isEmail($str){ if(!self::isEmpty($str)) return false; return preg_match("/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i",$str) ? true : false; } //手机号码验证 public static function isMobile($str){ $exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/"; if(preg_match($exp,$str)){ return true; }else{ return false; } } /** * URL验证,纯网址格式,不支持IP验证 */ public static function isUrl($str){ if(!self::isEmpty($str)) return false; return preg_match('#(http|https|ftp|ftps)://([w-]+.)+[w-]+(/[w-./?%&=]*)?#i',$str) ? true : false; } /** * 验证中文 * @param:string $str 要匹配的字符串 * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isChinese($str,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."]+$/" : "/^[x{4e00}-x{9fa5}]+$/u"; return preg_match($match,$str) ? true : false; } /** * UTF-8验证 */ public static function isUtf8($str){ if(!self::isEmpty($str)) return false; return (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true) ? true : false; } /** * 验证长度 * @param: string $str * @param: int $type(方式,默认min <= $str <= max) * @param: int $min,最小值;$max,最大值; * @param: string $charset 字符 */ public static function length($str,$type=3,$min=0,$max=0,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $len = mb_strlen($str,$charset); switch($type){ case 1: //只匹配最小值 return ($len >= $min) ? true : false; break; case 2: //只匹配最大值 return ($max >= $len) ? true : false; break; default: //min = 1000 && $timeArr[0] = 0 && $dateArr[1] = 0 && $dateArr[2] = 0 && $timeArr[0] = 0 && $timeArr[1] = 0 && $timeArr[2] </code>
<code>include("check.php"); $check = new VerifyAction(); //验证邮箱 $check_email = $check->isEmail($_POST['email']); if($check_email) { //是正确的邮箱 }else{ //邮箱填写有问题... } </code>
不知道你明白了么?如果不明白 加群讨论下告诉你 群:231566327
<code>include("check.php"); if($_SERVER['REQUEST_METHOD']=='POST'){ if(!VerifyAction::isEmpty($_POST['name'])){ die("用户名不能为空") ; }elseif(!VerifyAction::isEmail($_POST['email'])){ die( "无效邮箱账号"); } echo "验证通过"; } </code>

PHPは、特にWeb開発の分野で、最新のプログラミングで強力で広く使用されているツールのままです。 1)PHPは使いやすく、データベースとシームレスに統合されており、多くの開発者にとって最初の選択肢です。 2)動的コンテンツ生成とオブジェクト指向プログラミングをサポートし、Webサイトを迅速に作成および保守するのに適しています。 3)PHPのパフォーマンスは、データベースクエリをキャッシュおよび最適化することで改善でき、その広範なコミュニティと豊富なエコシステムにより、今日のテクノロジースタックでは依然として重要になります。

PHPでは、弱い参照クラスを通じて弱い参照が実装され、ガベージコレクターがオブジェクトの回収を妨げません。弱い参照は、キャッシュシステムやイベントリスナーなどのシナリオに適しています。オブジェクトの生存を保証することはできず、ごみ収集が遅れる可能性があることに注意する必要があります。

\ _ \ _ Invokeメソッドを使用すると、オブジェクトを関数のように呼び出すことができます。 1。オブジェクトを呼び出すことができるように\ _ \ _呼び出しメソッドを定義します。 2。$ obj(...)構文を使用すると、PHPは\ _ \ _ Invokeメソッドを実行します。 3。ロギングや計算機、コードの柔軟性の向上、読みやすさなどのシナリオに適しています。

繊維はPhp8.1で導入され、同時処理機能が改善されました。 1)繊維は、コルーチンと同様の軽量の並行性モデルです。 2)開発者がタスクの実行フローを手動で制御できるようにし、I/O集約型タスクの処理に適しています。 3)繊維を使用すると、より効率的で応答性の高いコードを書き込むことができます。

PHPコミュニティは、開発者の成長を支援するための豊富なリソースとサポートを提供します。 1)リソースには、公式のドキュメント、チュートリアル、ブログ、LaravelやSymfonyなどのオープンソースプロジェクトが含まれます。 2)StackOverFlow、Reddit、およびSlackチャネルを通じてサポートを取得できます。 3)開発動向は、RFCに従うことで学ぶことができます。 4)コミュニティへの統合は、積極的な参加、コード共有への貢献、および学習共有への貢献を通じて達成できます。

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHPは、シンプルな構文と高い実行効率を備えたWeb開発に適しています。 2。Pythonは、簡潔な構文とリッチライブラリを備えたデータサイエンスと機械学習に適しています。

PHPは死にかけていませんが、常に適応して進化しています。 1)PHPは、1994年以来、新しいテクノロジーの傾向に適応するために複数のバージョンの反復を受けています。 2)現在、電子商取引、コンテンツ管理システム、その他の分野で広く使用されています。 3)PHP8は、パフォーマンスと近代化を改善するために、JITコンパイラおよびその他の機能を導入します。 4)Opcacheを使用してPSR-12標準に従って、パフォーマンスとコードの品質を最適化します。

PHPの将来は、新しいテクノロジーの傾向に適応し、革新的な機能を導入することで達成されます。1)クラウドコンピューティング、コンテナ化、マイクロサービスアーキテクチャに適応し、DockerとKubernetesをサポートします。 2)パフォーマンスとデータ処理の効率を改善するために、JITコンパイラと列挙タイプを導入します。 3)パフォーマンスを継続的に最適化し、ベストプラクティスを促進します。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

Dreamweaver Mac版
ビジュアル Web 開発ツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール
