PHP function comments

Source: Internet
Author: User
Author of PHP function comments : Axglephp function usage instructions, application examples, simplified comments , I hope it will help you learn PHP. 1. Print_r  () Print the easy-to-understand information about variables. If it is an array, the structure information of the array is displayed. . For example: <PRE> <? PHP  $ = Array ('A' => 'apple', 'B' => 'bana', 'c' => Array ('X', 'y', 'Z' ));  Print_r ($  ); ?> </PRE> Axgle comments : View the structure information of any array, yesProgramA required tool for debugging. If any returned result is an array "function", you only need print_r to check the details at a glance! 2. Var_export  () Outputs or returns a variable string, indicating that the function returns structure information about the variable passed to the function, which is similar to print_r, the difference is that the returned representation is valid in PHP.Code. You can set the second parameter of the function  True  To return the expression of the variable. For example : <PRE> <? PHP  $ = Array (1, 2,Array ("A", "B", "C" ));  Var_export ( $  );  Echo "<HR>" ;  $ V = Var_export ( $ , True  );  Echo   $ V  ; ?> </PRE>Axgle comments : In the above example, $ V = Var_export ( $ , True ) PHP code is returned ~~ You can save it as a PHP file. What is saved 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 it fails File () Return False  . <PRE> <?PHP  //  Reads a file into an array.  $ Lines = File ('Test.txt' );  //  View the structure of this array  Print_r ( $ Lines  ); ?> </PRE> Axgle comments : File () Functions are a function that surprised me when I first came into contact with PHP. Compared with the previousC LanguageI 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 : <? PHP  Phpinfo  (); ?> Axgle comments : A simple function that keeps you updated on the rapid development of PHP-if you are closely following the development of PHP ~~~~ 5. File_get_contents () (Note: PHP 4> = 4.3.0, PHP 5 ) Read the entire file into a string. . File_get_contents () Functions are the first choice to read the content of a file into a string. If the operating system supports it, the memory ing technology will be used to enhance the performance. For example : <? PHP  $ Data = File_get_contents ('Test.txt' );  Echo   $ Data  ; ?> 6. File_put_contents (Note: PHP 5 ) Write a string directly to the file. . For example : <? PHP  //  Address of an image $ URL = "Http://...test.com/plmm.jpg" ;  //  Read Binary "string"  $ Data = File_get_contents ( $ URL  );  //  Save to your computer  File_put_contents ("Beauty .jpg ", $ Data  ); ?> Axgle comments : If you find that an image of a beauty image website is named like 1.jpg, 2.jpg...OK, use a for loop to capture all the "beautiful women". Don't be so excited that your girlfriend will be jealous. ~~~ 7. Function_exists  If the function exists, true is returned. For example: : <? PHP  //  If the function does not exist, you can 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 to obtain all defined PHP functions. For example : <PRE> <?PHP  $ Arr = Get_defined_functions  ();  Print_r ( $ Arr  ); ?> </PRE> Axgle comments : Now you know all the function names. If you want to know how to use a function, you can use http: //  Www.php.net/function_name can be found online, "manage all kinds of diseases, diagnose all kinds of problems and diagnose all kinds of problems, remove medicines to the disease ~~~~" 9. Get_declared_classes  Returns an array to obtain all defined PHP classes. For example : <PRE> <? PHP $ Arr = Get_declared_classes  ();  Print_r ( $ Arr  ); ?> </PRE> Axgle comments : You can see this function after Example 8 is run. Run this function in PhP4 to obtain only a few classes. However, if you use PhP5, you will see dozens of predefined PHP classes in this example! It can be seen that PhP5 is much more object-oriented. 10. Exit  Output the message and stop the current script. (Note: Like echo, this is not "Function", but a "statement" ). For example : <? PHP  Echo "Statement 1" ;  Exit ("The following statement 2 will not be output" );  Echo "Statement 2" ; ?> Axgle comments : It is useful to debug the program and find the wrong location. There are many useful PHP Functions And some very interesting PHP functions can be shared. I will introduce them later.

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.