33 common php questions and answers, 33 php questions and answers _ PHP Tutorial

Source: Internet
Author: User
Tags imagemagick
33 common php questions and answers, 33 php questions and answers. 33 common php questions and answers, 33 php questions and answers 1. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable (1), and links to 33 common php interview questions and answers, 33 php questions and answers

1. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable (1), and the URL linked to the current page is recorded in the predefined variable (2).

The code is as follows:
A: echo $ _ SERVER ['php _ SELF ']; echo $ _ SERVER ["HTTP_REFERER"];

2. the execution segment will be output (3 ).

The code is as follows:
Answer: 0

3. in HTTP 1.0, status code 401 indicates (4). if the "File Not Found" prompt is returned, the header function is available. The statement is (5 ).

The code is as follows:
Answer: (4) unauthorized (5) header ("HTTP/1.0 404 Not Found ");

4. The role of the array function arsort is (6); the role of the statement error_reporting (2047) is (7 ).

The code is as follows:
A: (6) reverse sort the array and maintain the index relationship (7) All errors and warnings

5. write a regular expression to ignore all JS/VBS scripts on the webpage (that is, remove the mark and its content): (9 ).

The code is as follows:
A:/<[^>]. *?>. *? <\/>/Si

6. install PHP using the Apache Module. in the http. conf file, first use the statement (10) to dynamically load the PHP module,

Then, use the statement (11) to make Apache process all files with the extension of php as PHP scripts.

The code is as follows:
A: (10) LoadModule php5_module "D:/xampp/apache/bin/php5apache2. dll"
(11) AddType application/x-httpd-php-source. phps
AddType application/x-httpd-php. php. php5. php4. php3. phtml

7. the statement include and require can both include another file to the current file. The difference is (12). to avoid multiple inclusion of the same file, you can use the statement (13) to replace them.

The code is as follows:
A: (12) include generates a warning when an exception occurs. require generates a fatal error (13) require_once ()/include_once ()

8. the attributes of the class can be serialized and saved to the session, so that the entire class can be restored later. the function to be used is (14 ).

The code is as follows:
Answer: serialize ()/unserialize ()

9. a function parameter cannot be a reference to a variable unless (15) is set to on.

The code is as follows:
A: allow_call_time_pass_reference

10. the meaning of left join in SQL is (16 ).

If tbl_user records the student name and student ID ),

Tbl_score records the student's student ID (ID), score (score), and subject (subject ),

To print the student name and the total score of each subject, you can use SQL statement (17 ).

The code is as follows:
Answer: (16) natural left outer join
(17) select name, count (score) as sum_score from tbl_user left join tbl_score on tbl_user.ID = tbl_score.ID group by tbl_user.ID

11 .. in PHP, heredoc is a special string and its end sign must be (18 ).

The code is as follows:
A: The row where the end identifier is located cannot contain any other characters ";"

12. use PHP to print the time format of the previous day in the format of 22:21:21

The code is as follows:
A: echo date ('Y-m-d H: I: S', strtotime ('-1 DAY '));

13. differences between echo (), print (), and print_r ()

The code is as follows:
A: echo is a language structure and has no return value. The print function is basically the same as echo. The difference is that print is a function and has a return value. print_r is a recursive print that outputs an array object.

14. how to implement string flip?

The code is as follows:
A: Use the strrev function. you are not allowed to write the strrev function using the built-in PHP function:
Strrev ($ str)
{
$ Len = strlen ($ str );
$ Newstr = '';
For ($ I = $ len; $ I >=0; $ I --)
{
$ Newstr. = $ str {$ I };
}
Return $ newstr;
}

15. implement the method of intercepting Chinese strings without garbled characters.

The code is as follows:
A: mb_substr ()

16. use php to write a simple query, find all the content named "zhang san" and print it out.

Table name User

Name Tel Content Date

Zhang San 13333663366 graduated from college-10-11

Michael Zhang graduated from 13612312331 undergraduate course-10-15

Zhang Si 021-55665566 graduated from technical secondary school 2006-10-15

The code is as follows:
A: SELECT Name, Tel, Content, Date FROM User WHERE Name = 'zhangsan'

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

Class test
{
Get_test ($ num)
{
$ Num = md5 (md5 ($ num). "En ");
Return $ num;
}
}

Answer: usage:

The code is as follows:
$ Get_test = new test ();
$ Result = $ get_test-> Get_test (2 );

The $ num variable is returned after two md5 operations. the parameter in 2nd md5 operations adds En after the first md5 ($ num) operation.

18. get the extension of a file in more than five ways

Requirement: dir/upload.image.jpg to find. jpg or. jpg,

The code is as follows:
A: You can obtain the extension of a file in more than five ways.
1)
Get_ext1 ($ file_name)
{
Return strrchr ($ file_name ,'.');
}
2)
Get_ext2 ($ file_name)
{
Return substr ($ file_name, strrpos ($ file_name ,'.'));
}
3)
Get_ext3 ($ file_name)
{
Return array_pop (explode ('.', $ file_name ));
}
4)
Get_ext4 ($ file_name)
{
$ P = pathinfo ($ file_name );
Return $ p ['extension'];
}
5)
Get_ext5 ($ file_name)
{
Return strrev (substr (strrev ($ file_name), 0, strpos (strrev ($ file_name ),'.')));
}

19. how to modify the SESSION survival time

This function allows you to process and display images in various formats. another common purpose of this function is to create images. Another option other than GD is ImageMagick, but this function library is not built in PHP and must be installed on the server by the system administrator. A: In fact, Session also provides the session_set_cookie_params () function (); to set the Session lifetime. this function must be called before the session_start () function is called:

<? Php
// Save for one day
$ LifeTime = 24*3600;
Session_set_cookie_params ($ lifeTime );
Session_start ();
$ _ SESSION ["admin"] = true;
?>

20. write a function to convert the string "open_door" to "OpenDoor" and "make_by_id" to "MakeById ".

The code is as follows:
A:
Function test ($ str ){
$ Arr1 = explode ('_', $ str );
// $ Arr2 = array_walk ($ arr1, ucwords ());
$ Str = implode ('', $ arr1 );
Return ucwords ($ str );
}
$ Aa = 'Open _ door ';
Echo test ($ aa );
?>

21. how can I use the php environment variable to get the content of a webpage address? How can I get the IP address?

The code is as follows:
A: $ _ SERVSR ['request _ URI ']
$ _ SERVER ['remote _ ADDR ']

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

The code is as follows:
Answer: (strtotime ('2017-3-6 ')-strtotime ('2017-2-5')/2007*24

23. the table has three columns a B c, which are implemented using SQL statements: When column A is greater than column B, select column A; otherwise, select column B, if Column B is greater than column C, column B is selected; otherwise, column C is selected.

The code is as follows:
A: select case when A> B then A else B end,
Case when B> C then B else C end
From test

24. briefly describe how to optimize the SQL statement execution efficiency in the project. In what ways can we analyze the SQL statement performance?

The code is as follows:
Answer: (1) select the most efficient table name order.
(2) join order in the WHERE clause
(3) avoid using '*' in the SELECT clause '*'
(4) replace HAVING clause with Where clause
(5) improve SQL efficiency through internal functions
(6) avoid using computation on index columns.
(7) to improve the efficiency of group by statements, you can filter out unnecessary records before group.

25. What are the differences between mysql_fetch_row () and mysql_fetch_array?

The code is as follows:
Mysql_fetch_row () stores a column of the database in a zero-based array. The first column is indexed 0 in the array, the second column is indexed 1, and so on. Mysql_fetch_assoc () stores a column of the database in an associated array. The index of the array is the column name, for example, if my database query returns the "first_name", "last_name", and "email" columns, the index of the array is "first_name", "last_name", and "email ". Mysql_fetch_array () can return the values of mysql_fetch_row () and mysql_fetch_assoc () at the same time.

26. what is the following code used? Please explain.

$ Date = '2014/1/123'; print ereg_replace ("([0-9] +)/([0-9] +)/([0-9] +) "," \ 2/\ 1/\ 3 ", $ date );

The code is as follows:
This is to convert a date from MM/DD/YYYY to DD/MM/YYYY. A good friend of mine told me that this regular expression can be split into the following statements. for such a simple expression, there is no need to disassemble it. it is purely for the convenience of explanation:
// Corresponding to one or more 0-9, followed by an oblique number $ regExpression = "([0-9] + )/"; // apply one or more values to 0-9, followed by another oblique sign $ regExpression. = "([0-9] +)/"; // corresponding to one or more 0-9 $ regExpression again. = "([0-9] +)"; as for \ 2/\ 1/\ 3, it is used to correspond to Parentheses. The first parenthesis is for the month,

27. what is the GD function library used?

The code is as follows:
A: This function allows you to process and display images in various formats. another common purpose of this function is to create images. Another option other than GD is ImageMagick, but this function library is not built in PHP and must be installed on the server by the system administrator.

28. how can I speed up page loading during your development?

The code is as follows:
A: It is enabled only when server resources are used. server resources are closed in time, and indexes are added to the database. static files, images, and other large files can be generated on the page on a separate server. Use the code optimization tool

29. The _ addslashes ___ function is generally used to prevent SQL injection vulnerabilities.

30. what is the difference between the transfer of value in PHP and the transfer of reference and transfer of address?

The code is as follows:
A: If a value is assigned to a row parameter, the modification to the row parameter does not affect the value of the row parameter.
The pass-through address is a special method for passing values, but it passes an address. it is not a common case that after an int is passed, both the real parameter and the row parameter point to the same object.

31. how to use javascript to determine whether a window has been blocked

The code is as follows:
A: get the return value of open (). if it is null, it is blocked.

33. what kind of method do you use to solve traffic problems for high-traffic websites?

The code is as follows:
A: First, check whether the server hardware is sufficient to support the current traffic.
Second, optimize database access.
Third, prohibit external leeching.
Fourth, control the download of large files.
Fifth, use different hosts to distribute major traffic
Sixth, use the traffic analysis and statistics software

The above is all the content of this article, hoping to help you learn php.

Lifecycle 1. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable (1), and linked...

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.