Good PHP face questions and Answers

Source: Internet
Author: User
Tags imagemagick
    1. Strrev ($STR)
    2. {
    3. $len =strlen ($STR);
    4. $newstr = ";
    5. for ($i = $len; $i >=0; $i--)
    6. {
    7. $newstr. = $str {$i};
    8. }
    9. return $newstr;
    10. }
Copy Code

15. The implementation of the text string interception without garbled method.

Answer: MB_SUBSTR ()

16. Use PHP to write a simple query, find all the names of "Zhang San" and print out the content

    1. Table name User
    2. Name Tel content Date
    3. Zhang 313,333,663,366 College Graduation 2006-10-11
    4. Zhang 313,612,312,331 Bachelor's degree 2006-10-15
    5. Zhang Si 021-55665566 secondary school 2006-10-15
    6. Answer: Select name,tel,content,date from user where name= ' Zhang San '
Copy Code

17. How to use the following class and explain what the following means?

    1. Class Test
    2. {
    3. Get_test ($num)
    4. {
    5. $num =MD5 (MD5 ($num). " En ");
    6. return $num;
    7. }
    8. }
Copy Code

A: Usage: $get _test = new Test (), $result = $get _test->get_test (2);

The $num variable is returned after two MD5, the 2nd time parameter in the MD5, after the first MD5 ($num) added en

18. Get the extension of a file using more than five different ways

Requirements: dir/upload.image.jpg, find. jpg or JPG,

A: Use more than five ways to get the extension of a file

    1. 1)

    2. Get_ext1 ($file _name)
    3. {
    4. Return STRRCHR ($file _name, '. ');
    5. }
    6. 2)
    7. GET_EXT2 ($file _name)
    8. {
    9. Return substr ($file _name, Strrpos ($file _name, '. '));
    10. }
    11. 3)
    12. GET_EXT3 ($file _name)
    13. {
    14. Return Array_pop (Explode ('. ', $file _name));
    15. }

    16. 4)

    17. GET_EXT4 ($file _name)
    18. {
    19. $p = PathInfo ($file _name);
    20. return $p [' extension '];
    21. }
    22. 5)
    23. GET_EXT5 ($file _name)
    24. {
    25. Return Strrev (substr (Strrev ($file _name), 0, Strpos (strrev ($file _name), '. '));
    26. }

Copy Code

19. How to modify the session lifetime

This library allows you to process and display a variety of formats, another common use is to make the document. Another option other than GD is ImageMagick, but the function library is not built into PHP and must be installed by the system administrator on the server A: In fact, the session also provides a function session_set_cookie_params (); To set the lifetime of the session, the function must be called before the session_start () function call:

    1. Save the day
    2. $lifetime = 24 * 3600;
    3. Session_set_cookie_params ($lifetime);
    4. Session_Start ();
    5. $_session["Admin"] = true;
    6. ? >
Copy Code

20. Write a function that enables the following functions: the string "Open_door" is converted to "Opendoor", "make_by_id" to "Makebyid". 30. Give an example of how you can speed up the loading of a page in your development process. Generates a static htmlb. Generate XMLC. You can save variable parameters in text without using the database as far as possible without the database. Use Zend to accelerate a:

    1. function test ($STR) {

    2. $arr 1=explode (' _ ', $str);
    3. $arr 2=array_walk ($arr 1,ucwords ());

    4. $str = Implode (' ', $arr 1);

    5. Return Ucwords ($STR);
    6. }
    7. $aa = ' Open_door ';
    8. echo Test ($AA);
    9. ?>

Copy Code

21. How do I get the content of a Web page address using PHP's environment variables? How do I get an IP address?

Answer: $_servsr[' Request_uri ']

$_server[' REMOTE_ADDR ']

22. Ask for the difference of two dates, for example, 2007-2-5 ~ 2007-3-6 Date Differential

Answer: (Strtotime (' 2007-3-6 ')-strtotime (' 2007-2-5 '))/3600*24

23. The table has a B C three columns, implemented with the SQL statement: When column A is greater than column B, select column B otherwise select column B, when column B is greater than column C, select column C otherwise.

A: Select Case is A>b then a else b end,case if B>c then B else C Endfrom test

24. Briefly describe the ways in which the SQL statement performance is optimized in the project, and in what ways do you analyze it?

Answer: (1) Select the most efficient table name order

(2) connection order in the WHERE clause

(3) Avoid using ' * ' in the SELECT clause

(4) Replace the HAVING clause with a WHERE clause

(5) Improve SQL efficiency with intrinsic functions

(6) Avoid using calculations on indexed columns.

(7) Improve the efficiency of the group BY statement by filtering out unwanted records before group by.

What is the difference between 25.mysql_fetch_row () and mysql_fetch_array ()?

Mysql_fetch_row () stores a column of the database in a zero-based array, the first column in the array index 0, the second column at index 1, and so on. MYSQL_FETCH_ASSOC () stores a column of the database in an associative array, the index of the array is the column name, for example, my database query back to "First_Name", "last_name", "e-mail" three fields, the index of the array is "first _name "," last_name "and" email ". Mysql_fetch_array () can send back the values of Mysql_fetch_row () and MYSQL_FETCH_ASSOC () at the same time.

26. What does the following code do for you? Please explain. $date = ' 08/26/2003 ';p rint ereg_replace ("([0-9]+)/([0-9]+]/([0-9]+)", "\\2/\\1/\\3", $date);

This is the conversion of a date from MM/DD/YYYY format to dd/mm/yyyy format. A good friend of mine told me that this regular expression can be disassembled into the following statement, for such a simple representation is actually no need to disassemble, purely for the convenience of explanation:

Corresponds to one or more 0-9, followed by an oblique number $regexpression = "([0-9]+)/";//should be one or more 0-9, followed by another oblique number $regexpression. = "([0-9]+)/";//corresponds one or more 0-9$regexpression. = "([0-9]+)"; \\2/\\1/\\3 is used to correspond to parentheses, the first pair of parentheses is the month,

What is 27.GD function library for?

A: This library allows you to process and display a variety of formats, another common use is to make the document. Another option other than GD is ImageMagick, but the function library is not built into PHP and must be installed by the system administrator on the server

28. Please explain in your development process what method to speed up the loading speed of the page A: To use the server resources to open, timely shutdown server resources, database Add index, page can generate static, picture and other large file separate server. Use the Code optimization tool.

29. Prevent SQL injection vulnerability generally with the __addslashes___ function.

What is the difference between a value in 30.php and a pass-through or address? A: The value of the argument is the value assigned to the parameter to the row parameter, so the modification of the parameter does not affect the value of the argument.

An address is a special way of transmitting a value, except that he passes an address, not an ordinary one, such as an int. After the address, both the argument and the row parameter point to the same object

31. How to tell if a window has been masked by JavaScript a: Gets the return value of open (), or null if it is blocked

33. What are the ways you can solve traffic problems for large-volume websites?

A: First, verify that the server hardware is sufficient to support current traffic

Second, optimize database access.

Third, prohibit the external hotlinking.

Four, control the download of large files.

V. Use different hosts to divert the main flow

VI, using traffic analysis statistics software

The above to share some PHP face questions and related answers, hope to help you.

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