Php interview questions

Source: Internet
Author: User
Php interview question 1. use PHP to print the time format of the previous day in the format of 22:21:21
Solution: echo date ('Y-n-d H: I: S', strtotime ('-1 DAY '));
Cause:
Format
A Morning and afternoon values in lower case Am or pm
A Upper-case morning and afternoon values AM or PM
D The day of the month, which has two digits leading to zero 01 to 31
D The day of the week. The text indicates three letters. Mon to Sun
F The month in the complete text format, such as January or March. January to December
G Hour, 12-hour format, no leading zero 1 to 12
G Hour, in 24-hour format, no leading zero 0 to 23
H Hour, 12-hour format, with leading zero 01 to 12
H Hour, in 24-hour format, with a leading zero 00 to 23
I Minutes with a leading zero 00 to 59>
I When it is enabled or not If this parameter is set to 1, otherwise it is set to 0.
J The day of the month, with no leading zero 1 to 31
L (lowercase letters of "L) Day of week, complete text format Sunday to Saturday
L Is it a leap year? If the leap year is 1, otherwise it is 0
M Number indicates the month, with a leading zero 01 to 12
M The month abbreviated to three characters. Jan to Dec
N Number indicates the month, with no leading zero 1 to 12
O Hours different from Greenwich Mean Time For example: + 0200
R Date in RFC 822 format Example: Thu, 21 Dec 2000 16:01:07 + 0200
S Number of seconds, with a leading zero 00 to 59>
S English suffix after the number of days per month, 2 characters St, nd, rd or th. It can be used with j.
T Number of days in a given month 28 to 31
T Time zone of the local machine For example, EST and MDT are in full text format in Windows. for example, "Eastern Standard Time" is displayed in Chinese ").
W The day of the week, represented by a number 0 (Sunday) to 6 (Saturday)
W The week of the year in ISO-8601 format, starting from Monday each week (new in PHP 4.1.0) Example: 42 (42nd weeks of the current year)
Y The year in which the four digits represent the complete number. Example: 1999 or 2003
Y A two-digit year Example: 99 or 03
Z The day of the year. 0 to 366

2. templates that can be used to split HTML and PHP
Solution: in fact, PHP itself is a template engine. I have used smarty. Common examples include PHPLib, FastTemplate, and Savant. here we have a template engine list.
: Http://www.sitepoint.com/forums/showthread.php? T = 123769

3. what tools are used for version control?
Solution: CVS and SVN. SVN is known as the next generation of CVS and has powerful functions. However, CVS is a veteran with a high market share. I have been using SVN for a long time. The question is what tools are used. well, this may require the following answers: CVS Server on Apache as the Server, WinCVS as the client, and Subversion on Apache/DAV as the Server, tortoiseSVN is used as the client, or Subclipse is used as the client.

4. how to implement string flip?
Solution: Use the strrev function. if you are not allowed to use the built-in PHP function, write it yourself:
Strrev ($ str)
{
$ Len = strlen ($ str );
$ Newstr = '''';
For ($ I = $ len; $ I >=0; $ I --)
{
$ Newstr. = $ str {$ I };
}
Return $ newstr;
}

5. how to optimize the MYSQL database?
My answer:
(1 ). in terms of database design, this is the responsibility of DBA and impact ect. a database with a good design structure should be de-normalized when necessary (I don't know what the Chinese translation is ), some data redundancy is allowed to avoid JOIN operations to improve query efficiency.
(2 ). in terms of system architecture design, the table is hashed, and massive data is hashed into several different tables. fast and Slow tables: only the latest data is retained. slow tables are archived in history. cluster, master server Read &
Write, read only from the server, or N servers. each server is a Master.
(3). (1) and (2) better than PHP Programmer's requirements. it doesn't matter. check whether there is any less index.
(4 ). write efficient SQL statements to see if there are any inefficient SQL statements, such as generating full connections to Cartesian products, a large number of Group By and order by statements, and no limit. when necessary, encapsulate the database logic in the stored procedure of the DBMS. cache query results and explain each SQL statement
(5). all the results are required. only necessary data is obtained from the database. for example, you can query the number of comments of an article, select count (*)... where article_id =? You can. do not select *... where article_id =? Then, msql_num_rows only transmits the required SQL statements. for example, if you modify only the title when modifying an article, update... set title =? Where article_id =? Do not set content =? (Large text)
(6). use different storage engines when necessary. for example, InnoDB can reduce deadlocks. HEAP can increase the query speed by an order of magnitude.

6. about transaction processing?
Solution: Just as A programming language would have an example that promises "Hello World", this is an example of A transferring $50 to B's account in the textbooks of this database. just answer this question. as far as I know, MySQL enterprises seldom use MySQL for transaction processing. moreover, Oracle has acquired InnoDB.

7. how to achieve maximum load using apache + mysql + php
Solution:

8. the Chinese string is intercepted without garbled characters.
Solution: mb_substr ()

9. differences between echo (), print (), and print_r ()
Solution: 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 recursive printing and used to output array objects.

10. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable. the URL linked to the current page is recorded in the predefined variable.
Solution: echo $ _ SERVER ['php _ SELF ']; echo $ _ SERVER ["HTTP_REFERER"];
11. Execution section Will output ??
Solution: 0
12. what is the meaning of status code 1.0 in HTTP 401? if the "File Not Found" prompt is returned, the header function is available and the statement is used.
Solution: unauthorized header ("HTTP/1.0 404 Not Found ");
13. the arsort function is used to sort the array in reverse order and maintain the index relationship. The role of the error_reporting (2047) statement is (All errors and warnings ).
14. what is the format of the database connection string in PEAR ()?
15. write a regular expression to overwrite all JS/VBS scripts on the webpage (that is, remove the script tag and its content ):(/ ]. *?>. *? <\/Script>/si)
16. install PHP using the Apache module. in conf, first use statement (1) to dynamically load the PHP module, and then use statement (2) to make Apache process all files with the extension of php as PHP scripts.
Solution: (1) LoadModule php5_module "D:/xampp/apache/bin/php5apache2. dll" (2) AddType application/x-httpd-php-source. phps
AddType application/x-httpd-php. php. php5. php4. php3. phtml
17. the Statement include and require can both include another file to the current file. what is the difference between them? to avoid multiple inclusion of the same file, you can replace them with statements.
Solution: When an exception occurs, include generates a warning. require generates a fatal error (13) require_once ()/include_once ()
18. attributes of a class can be serialized and saved to the session, so that the entire class can be restored later. This function is used (serialize ()/unserialize ())
19. a function parameter cannot be a reference to a variable unless (allow_call_time_pass_reference) is set to on in php. ini.
20. the meaning of left join in SQL is (natural LEFT outer JOIN ).
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 the SQL statement: 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
21. in PHP, heredoc is a special character string and its end mark must be (the row where the end identifier is located cannot contain any other characters ";").
22. write a function to traverse all files and subfolders in a folder.
Solution :/**
* Traverse the directory and save the result to an array. Php4 and above are supported. Php5 and later use the scandir () function to replace the while loop.
* @ Param string $ dir
* @ Return array
*/
Function my_scandir ($ dir)
{
$ Files = array ();
If ($ handle = opendir ($ dir )){
While ($ file = readdir ($ handle ))! = False ){
If ($ file! = "..." & $ File! = "."){
If (is_dir ($ dir. "/". $ file )){
$ Files [$ file] = rec_scandir ($ dir. "/". $ file );
} Else {
$ Files [] = $ file;
}
}
}
Closedir ($ handle );
Return $ files;
}
}
23. briefly describe the implementation principles of unlimited classification in the forum.
24. design a webpage so that a full screen window is displayed when it is opened, which contains a text box and a button. After entering information in the text box, you can click the button to close the window, but the entered information is displayed on the main page.

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.