/*
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;
}
}