Some Novice PHP learning experience

Source: Internet
Author: User
Tags abstract array arrays interface variables php code php script variable

1, the curly brace "{}" can manipulate the string as an array of "[]" operations to get the character at the specified position.

The 2,php tag "<?php?>" can not write an end tag in a standalone PHP script, which is an error in order to avoid unexpected spaces causing output.   You can use annotations to mark the end of the script. 3,echo is a grammatical structure, not a function.   The following string is followed by a comma "," which is more efficient. 4, in an array, 1, ' 1 ', and true are all cast to 1 when indexed.   and ' 01 ' will not be converted, and will be processed by string. 5, it is illegal to write the code of a class in different PHP tags, and will report a syntax error.   And the function is fine. The difference and relationship between 6,session and cookies.
    • The session is saved on the server and the cookie is stored on the client's browser;
    • Session save can be the file on the hard disk, the database, the Memcached,cookie can be saved to the hard disk (persistent cookie) and memory (conversation cookie);
    • There are two ways to pass the session_id, one is a cookie, and the other is a get way (you can specify the variable name to save session_id by Session.name configuration entry).
7, obtain the current timestamp with $_server[' request_time '] instead of time (), you can reduce the function call, more efficient. 8, check whether the string exceeds a certain length can replace the strlen () function with the syntax of Isset ($STR {n}), for example, to determine whether the $a length is over 5 and can be judged by isset ($a {5}).   This is more efficient.   The 9,header () function is to exit, otherwise the following code will execute.   10, the large array is passed by reference, reduce memory footprint, run out of unset ().   11, the database connection in use when the establishment, completely used up remember to close the connection. Limitations of 12,set_time_limit ().   You can limit the running time of the script itself, for instance, the system () function, stream operation, database query, and so on, for external execution time. The difference between 13,abstract and interface:
    • Abstract can have a Non-abstract method, interface not;
    • Abstract the access control of the method can be protected, and interface must be public;
    • Abstract can only be inherited, of course, a class can inherit only one class, and a class may implement multiple interface.
The difference between 14,echo,print,print_r,var_dump,var_export:
    • Echo,print is a syntactic structure, not a function, and can only display basic types, cannot display arrays and objects, others are functions, and can display arrays and objects;
    • echo can display multiple variables, separated by commas;
    • Print_r the second parameter can determine whether it is an output variable or a variable as the return value;
    • Var_dump prints the details of the variable, such as length and type, and can pass multiple variables as arguments;
    • Var_export returns a valid PHP code format.
15, verify the mailbox: Filter_var ($email, Filter_validate_email); 16, get the file name extension method:
    • One, PathInfo ($filename), take the extension value.

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

17, the file lock function flock--the constant argument. Shared locks (read operations)--lock_sh exclusive locks (write operations)--LOCK_EX release locks (whether shared or exclusive)--lock_un blocking--LOCK_NB

You can release the lock operation through the fclose () function.

18, verify that the string is a legitimate IP:

No regular, directly with Ip2long (), the legal return of the number, the law returns false.

19,php 5.3, you can use __dir__ to get the directory of the current script, no more 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.