Four small PHP functions. 1. how to view the variable content there is a var_dump ($ var) function in php4 to dump the content of a variable (various types of variables ), but the output of this function is not suitable for the html page. 1. how to view the variable content
Php4 has a var_dump ($ var) function used to dump the content of a variable (various types of variables), but the output of this function is not suitable for display on the html page. You can write a function as follows:
Function dump ($ var ){
Echo"
";
Var_dump ($ var );
Echo"
";
}
Very suitable for debugging!
In php3, only a recursive method can be used to dump the content of an array, which is powerless to the object. It seems that the Dump_Array function in the previous article is such a function. :)
II. static variables
Function test ()
{
Static $ s_val;
$ S_val + = 2;
Return $ s_val;
}
Echo test (); // 2
Echo test (); // 4
?>
3. a method to avoid multiple occurrences of the same celebrity
# -------------- Avoid the same name -------------
For ($ checkname = 0; $ checkname <$ num; $ checkname ++)
{
If ($ name [$ checkname] = $ name [$ num])
{
$ Num --;
Break;
}
}
4. get the extension of a file
Use this small function:
Function fileextname ($ filename)
{
$ Retval = "";
$ Pt = strrpos ($ filename ,".");
If ($ pt) $ retval = substr ($ filename, $ pt + 1, strlen ($ filename)-$ pt );
Return ($ retval );
Php4 has a var_dump ($ var) function used to dump the content of a variable (various types of variables), but the output of this function is not suitable for html pages...