PHP function application clarification, using examples to streamline comments, hope to help you learn php. 1. print_r () prints easy-to-understand information about Variables. if it is an array, the structure information of the array is displayed. for example: pre? Php $ a = array ('a' = 'apple', 'B PHP function application clarification, using examples, streamlined comments, hope to help you learn php.
1. print_r ()
Prints easy-to-understand information about Variables. if it is an array, it displays the structure information of the array.
For example:
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
Axgle comment: Viewing the structure information of any array is a necessary tool for program debugging. If any returned result is an array "function", you only need print_r to see everything at a glance!
2. var_export ()
Output or return the string representation of a variable
This function returns the structure information about the variables passed to the function. it is similar to print_r (). The difference is that the returned result is a legitimate PHP code.
You can set the second parameter of the function to TRUE to return the expression of the variable.
For example:
$a = array (1, 2, array ('a', 'b', 'c'));
var_export ($a);
echo '';
$v = var_export($a, TRUE);
echo $v;
?>
Axgle comment: In the above example, $ v = var_export ($ a, TRUE) returns the php code ~~ Then you can keep it as a php file.
What do I do if I keep it as a php file? This can be used as a "cache". you can include it directly when necessary.
3. file ()
File () returns the object as an array. Each element in the array is a corresponding line in the file, including line breaks. If file () fails, FALSE is returned.
// Read an object into the array.
$ Lines = file('test.txt ');
// View the structure of this array
Print_r ($ lines );
?>
Axgle comment: the file () function is a function that surprised me when I first came into contact with php. In C and vb
I felt that there was no more convenient file read/write method than the file () function.
4. phpinfo ()
Print php-related information, such as the PHP version, function support, and global variables.
For example:
Phpinfo ();
?>
Axgle comment: a simple function that allows you to understand the rapid development of php at all times-if you pay close attention to the development of php ~~~~
5. file_get_contents () (Note: PHP 4> = 4.3.0, PHP 5)
Reading all files into a string. file_get_contents () is the preferred method for reading the file content into a string. If the control system supports, the memory ing technique will be applied to enhance the performance.
For example:
$ Data = file_get_contents('test.txt ');
Echo $ data;
?>
6. file_put_contents (note: PHP 5)
Write a string directly into the file.
For example:
// Address of an image
$ Url = 'http: // ..test.com/plmm.jpg ';
// Read the binary "string"
$ Data = file_get_contents ($ url );
// Keep it in your computer
File_put_contents('female .jpg ', $ data );
?>
Axgle comments: If you upload an image of a beauty Image website, the name of the image is as follows: 1.JPG, 2.jpg...