search
Homephp教程php手册php通用检测函数集(2)

php通用检测函数集(2)

Jun 13, 2016 am 10:20 AM
phpforfunctionjudgmentefficientDetectionuseURLUniversal

// 函数名:CheckWebAddr($C_weburl)
// 作 用:判断是否为有效网址
// 参 数:$C_weburl(待检测的网址)
// 返回值:布尔值
// 备 注:无
//-----------------------------------------------------------------------------------
-------
function CheckWebAddr($C_weburl)
{
if (!ereg("^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $C_weburl))
{
return false;
}
return true;
}
//-----------------------------------------------------------------------------------
-------


//-----------------------------------------------------------------------------------
-------
// 函数名:CheckEmpty($C_char)
// 作 用:判断字符串是否为空
// 参 数:$C_char(待检测的字符串)
// 返回值:布尔值
// 备 注:无
//-----------------------------------------------------------------------------------
-------
function CheckEmptyString($C_char)
{
if (!is_string($C_char)) return false; //是否是字符串类型
if (empty($C_char)) return false; //是否已设定
if ($C_char==) return false; //是否为空
return true;
}
//-----------------------------------------------------------------------------------
-------

//-----------------------------------------------------------------------------------
-------
// 函数名:CheckLengthBetween($C_char, $I_len1, $I_len2=100)
// 作 用:判断是否为指定长度内字符串
// 参 数:$C_char(待检测的字符串)
// $I_len1 (目标字符串长度的下限)
// $I_len2 (目标字符串长度的上限)
// 返回值:布尔值
// 备 注:无
//-----------------------------------------------------------------------------------
-------
function CheckLengthBetween($C_cahr, $I_len1, $I_len2=100)
{
$C_cahr = trim($C_cahr);
if (strlen($C_cahr) if (strlen($C_cahr) > $I_len2) return false;
return true;
}
//-----------------------------------------------------------------------------------
-------

//-----------------------------------------------------------------------------------
-------
// 函数名:CheckUser($C_user)
// 作 用:判断是否为合法用户名
// 参 数:$C_user(待检测的用户名)
// 返回值:布尔值
// 备 注:无
//-----------------------------------------------------------------------------------
-------
function CheckUser($C_user)
{
if (!CheckLengthBetween($C_user, 4, 20)) return false; //宽度检验
if (!ereg("^[_a-zA-Z0-9]*$", $C_user)) return false; //特殊字符检验
return true;
}
//-----------------------------------------------------------------------------------
-------

//-----------------------------------------------------------------------------------
-------
// 函数名:CheckPassword($C_passwd)
// 作 用:判断是否为合法用户密码
// 参 数:$C_passwd(待检测的密码)
// 返回值:布尔值
// 备 注:无
//-----------------------------------------------------------------------------------
-------
function CheckPassword($C_passwd)
{
if (!CheckLengthBetween($C_passwd, 4, 20)) return false; //宽度检测
if (!ereg("^[_a-zA-Z0-9]*$", $C_passwd)) return false; //特殊字符检测
return true;
}
//-----------------------------------------------------------------------------------
-------

//-----------------------------------------------------------------------------------
-------

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.