Four PHP application small function _php Tutorial

Source: Internet
Author: User
How to view the contents of a variable

There is a var_dump ($var) function in PhP4 that dumps the contents of a variable (variables of various types), except that the output of this function is not suitable for display in an HTML page. You can write a function like this:
function Dump ($var) {
echo "
";
Var_dump ($var);
echo "
";
}

Great for commissioning!

In PhP3, you can only use recursive method to dump the contents of an array, there is nothing for object. As if the Dump_array function of the previous article is such a function. :)

Second, static variables
function test ()
{
Static $s _val;
$s _val+=2;
return $s _val;
}

echo Test ();//2
echo Test ();//4
?>

Iii. a method of avoiding multiple occurrences with celebrities
#----------------Avoid the same name-------------

for ($checkname =0; $checkname < $num; $checkname + +)
{
if ($name [$checkname]== $name [$num])
{
$num--;
Break
}
}

Iv. Obtaining an extension of a file
With this small function you can:

function Fileextname ($filename)
{
$retval = "";
$pt =strrpos ($filename, ".");
if ($pt) $retval =substr ($filename, $pt +1, strlen ($filename)-$pt);
return ($retval);

http://www.bkjia.com/PHPjc/532195.html www.bkjia.com true http://www.bkjia.com/PHPjc/532195.html techarticle How to view variable contents there is a var_dump ($var) function in PhP4 to dump the contents of a variable (various types of variables), except that the output of this function is not suitable for the HTML page ...

  • 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.