PHP string check class (for your own use)

Source: Internet
Author: User

/*
String check class
* @ Author sanshi
QQ: 35047205
Email: sanshi0815@tom.com
MSN: sanshi0815@tom.com

*/
Class checkbase
{
Function checkbase ()
{
}
/*
Used to check whether the string is null
* @ Param $ STR check field
* @ Param $ isstr if the field may have unique characters of the number or bool type
Returns true if it is null.
*/
Function strisnull ($ STR, $ isstr = true)
{
Return $ isstr? (Empty ($ Str )? True: false)
:( Isset ($ Str )? False: True );
}
/*
Comparison between string and Regular Expression
@ Param $ STR string to be compared
@ Param $ regular expression to be compared with pattern
Returns true when compared with the regular expression.
*/
Function strcomparepattern ($ STR, $ pattern)
{
If (ereg ($ pattern, $ Str ))
{
// Return is found
Return true;
}
Return false;
}
/*
Judge the length of a string
@ Param $ STR the string to be checked
@ Param $ Max maximum length
@ Param $ min minimum length
Returns true if it meets the requirements.
*/
Function strcomparelen ($ STR, $ Max, $ min = 1)
{
$ Len = strlen ($ Str );
$ Max = empty ($ max )? $ Len: $ Max;
Return ($ Len> $ max | $ Len <$ min )? False: true;
}
/*
Information processing, jump to the page
@ Param $ page the page to jump
@ Param $ MSG prompt information
*/
Function MSG ($ page, $ MSG)
{
$ MSG = empty ($ MSG )? '':"? MSG = ". base64_encode ($ MSG );
$ Url = $ page. $ MSG;
If (@ header ("Location:". $ URL ))
{
Echo "<meta http-equiv = Refresh content = '0; url =". $ URL. "'> ";
}
Exit ();
}

/*

Chinese string Truncation

*/

Function chinasubstr ($ STR, $ Len = '', $ replace = '...')
{
$ Len = empty ($ Len )? Strlen ($ Str): $ Len;
$ Temp = substr ($ STR, 0, $ Len );
$ CHR = ord (substr ($ temp, strlen ($ temp)-1 ));
$ Temp = ($ CHR >=161 & $ CHR <= 255 )? Substr ($ STR, 0, $ Len + 1): $ temp;
Return $ Len <strlen ($ Str )? $ Temp. $ Replace: $ temp;
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.