Four PHP app small function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Related Article

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.