How to learn PHP for beginners

Source: Internet
Author: User
Tags learn php for beginners php for beginners
1. Braces {} can operate strings like [] Operation arrays to obtain characters at the specified position. 2. PHP tag & lt ;? Php? & Gt; you can leave the end tag in an independent PHP script. This is to avoid errors caused by unexpected spaces. You can use comments to indicate the end of the script. 3, echo is the syntax knot... "> <LINKhref =" http://www.php100.com//sta

 

1. Braces "{}" can operate strings like "[]" to get characters at the specified position.

2. PHP tag""You can leave the end tag in an independent PHP script. This is to prevent unexpected spaces from leading to output errors. You can use comments to indicate the end of the script. 3. echo is a syntax structure, not a function. Use the comma "," when followed by multiple strings for better efficiency. 4. In the array, when 1, '1', and true are indexes, they are forcibly converted to 1. '01' will not be converted and will be processed according to the string. 5. It is invalid to write the code of a class in different PHP labels. A syntax error is reported. The function is fine. 6. Differences and relationships between sessions and cookies.
  • Session is saved on the server, and cookie is saved on the client browser;
  • Session storage can be files, databases, and memcached on the hard disk. Cookies can be saved to the hard disk (persistent cookie) and memory (session cookie );
  • Session_id can be transmitted in two ways: cookie and get (the session. name configuration item can be used to specify the variable name for saving session_id ).
7. Use $ _ SERVER ['request _ time'] instead of TIME () to obtain the current timestamp, which can reduce callback function calls and improve efficiency. 8. Check whether the length of the string exceeds a certain length. Use the isset ($ str {n}) syntax to replace strlen () function. For example, determine whether the length of $ a exceeds 5, you can use isset ($ a {5. This is more efficient. 9. exit after the header () function; otherwise, the code will be executed later. 10. The large array is passed by reference to reduce memory usage. When it is used up, it is unset (). 11. The database connection is established only when it is in use. When it is used up, remember to close the connection. 12, set_time_limit () limitations. Only the running time of the script itself can be limited, and the external execution time cannot be controlled, such as: system () function, stream operation, database query, etc. 13. Differences between abstract and interface:
  • Abstract can have non-abstract methods, but interface cannot;
  • Abstract The method access control can have protected, and the interface must be public;
  • Abstract can only be inherited. Of course, a class can only inherit one class, while a class can implement multiple interfaces.
14. Differences between echo, print, print_r, var_dump, and var_export:
  • Echo and print are syntax structures, not functions, and can only display basic types. Arrays and objects cannot be displayed. Others are functions, and arrays and objects can be displayed;
  • Echo can display multiple variables separated by commas;
  • The second parameter of print_r determines whether to output the variable or use the variable as the return value;
  • Var_dump prints detailed information about a variable, such as its length and type. Multiple variables can be passed as parameters;
  • Var_export returns a valid PHP code format.
15. Verification email: filter_var ($ email, FILTER_VALIDATE_EMAIL); 16. How to get the file extension:
  • 1. pathinfo ($ filename), which is the value of extension.

 

 

 

  • 2. end (explode ('.', $ filename )).

 

 

 

17. Constant parameter of the file lock function flock. Shared lock (read operation) -- LOCK_SH exclusive lock (write operation) -- LOCK_EX release lock (whether shared or exclusive) -- LOCK_UN anti-blocking -- LOCK_NB

You can use the fclose () function to release the lock operation.

18. Verify whether the string is a valid IP address:

Use ip2long () directly without regular expression. If it is valid, a number is returned. If it is invalid, false is returned.

19. Starting from PHP 5.3, you can use _ DIR _ to obtain the directory where the current script is located. You no longer need to use realpath (_ FILE.

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.