PHP Function Learning php function Reviews _php Tutorial

Source: Internet
Author: User
Tags phpinfo
1.print_r ()
Prints easy-to-understand information about the variable, and if it is an array, displays the structure information for the arrays.
For example:
Copy CodeThe code is as follows:
$a = Array (' a ' = = ' Apple ', ' B ' + = ' banana ', ' c ' = = Array (' x ', ' y ', ' z '));
Print_r ($a);
?>

Axgle Reviews: Viewing the structure information of any array is an essential tool for program debugging. For any returned result is an array of "functions", as long as print_r, all the things at a glance!
2.var_export ()
Outputs or returns a string representation of a variable
This function returns the structure information about the variable passed to the function, similar to Print_r (), unlike the PHP code whose returned representation is valid.
You can return the representation of a variable by setting the second argument of the function to TRUE.
For example:
Copy CodeThe code is as follows:
$a = Array (1, 2, Array ("A", "B", "C"));
Var_export ($a);
echo "";
$v = Var_export ($a, TRUE);
Echo $v;
?>

Axgle Reviews: In the above example, $v = Var_export ($a, TRUE) returns the PHP code OH ~ ~ ~ so you can save it as a PHP file.
What do I save as a php file? Oh, this can be used as a "cache", when needed, you can include it directly.
3.file ()
File () returns the files as an array. Each element in the array is the corresponding line in the file, including the newline character. FALSE If the failed file () is returned.
Copy CodeThe code is as follows:
Reads a file into the array.
$lines = File (' Test.txt ');
View the structure of this array
Print_r ($lines);
?>

Axgle Reviews: The file () function is a function I was very surprised at the beginning of my exposure to PHP. Compared to the previous I in C language and VB
The extremely troublesome experience of file reading and writing made me feel that there was no more convenient way to read and write files than the file () function.
4.phpinfo ()
Print information about PHP, such as PHP version, feature support, global variables, and more.
For example:
Phpinfo ();
?>
Axgle Reviews: A simple function that keeps you abreast of the rapid development of PHP---if you pay close attention to the development of PHP ~ ~ ~
5.file_get_contents () (Note: PHP 4 >= 4.3.0, PHP 5)
Reads the entire file into a string. The File_get_contents () function is the preferred method for reading the contents of a file into a string. If operating system support also uses memory-mapping techniques to enhance performance.
For example:
$data = file_get_contents (' test.txt ');
Echo $data;
?>
6. File_put_contents (Note: PHP 5)
Writes a string directly to the file.
For example:
The address of an image
$url = "Http://...test.com/plmm.jpg";
Read binary "string"
$data =file_get_contents ($url);
Save it to your own computer.
File_put_contents ("beauty. jpg", $data);
?>
Axgle Reviews: If you find a beautiful picture of the image of the site name is such as 1.jpg,2.jpg ...
OK, with a For loop, take all the "beauties" down, don't be so excited so that your girlfriend
Jealous, huh ~ ~ ~
7.function_exists
Returns True if the function exists
For example:
If the function does not exist, customize the function
if (!function_exists (' file_put_contents ')) {
function file_put_contents ($filename, $data) {
$FP =fopen ($filename, "WB");
Fwrite ($fp, $data);
Fclose ($FP);
}
}
?>
8.get_defined_functions
Returns an array that gets all the defined PHP functions.
For example:
Copy CodeThe code is as follows:
$arr = Get_defined_functions ();
Print_r ($arr);
?>

Axgle Reviews: Now you know all the function names. If you want to understand the usage of a function, you can use the form as Http://www.php.net/function_name online access, "package cures all kinds of diseases, miscellaneous diagnosis, Charm ~ ~ ~ ~ ~ ~ ~"
9.get_declared_classes
Returns an array that gets all the defined PHP classes.
For example:
Copy CodeThe code is as follows:
$arr = Get_declared_classes ();
Print_r ($arr);
?>

Axgle Reviews: Believe this function you can see in example 8 after running. There are only a few classes to run this function in PhP4, but if you use PHP5, you will see dozens of predefined PHP classes in this example! Visible PHP5 has been enhanced in terms of object-oriented aspects.
10.exit
Outputs the message and stops the current script. (Note: Like Echo, this is not a "function", but a "statement").
For example:
echo "Statement 1";
Exit ("Statement 2 below does not output");
echo "Statement 2";
?>
Axgle Reviews: It is useful to debug a program and find the location of the error.
There are a lot of useful PHP functions, and there are some very interesting PHP functions to share, and I'll introduce you sometime.

http://www.bkjia.com/PHPjc/325694.html www.bkjia.com true http://www.bkjia.com/PHPjc/325694.html techarticle 1.print_r () prints easy-to-understand information about variables, which, if they are arrays, displays the structure information of the array. For example: Copy code code as follows: PHP $a = array (' A ' = ' apple ', ' b ' = ' ...

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