PHP classic interview questions (Basic I) with answers. Interview and written examination are often indispensable for job hunting and recruitment. as a php programmer, more or less will have similar experiences. The following are the PHP interview questions I have collected and compiled, it is hoped that there will always be interviews and written examinations for job seeking and recruitment for colleagues. as a php programmer, there will be more or less similar experiences ...... The following are my PHP interview questions collected and sorted out. I hope to help my colleagues and find a suitable php development job! (Three in total)
The following are interview questions (1)
1. use PHP to print the time format of the previous day in the format of 22:21:21 (2 points)
Echo date ('Y-m-d H: I: S', strtotime ('-1 DAY '));
Or
$ Yesterday = time ()-(24*60*60 );
Echo 'Today: '. date ('Y-m-d H: I: s'). "n ";
Echo 'Yesterday: '. date ('Y-m-d H: I: S', $ yesterday). "n ";
2. differences between echo (), print (), and print_r () (3 points)
Echo is a PHP statement, print and print_r are functions, and the statement does not return values. the function can return values (even if it is not used)
Print can only print values of simple type variables (such as int and string)
Print_r can print values of complex types of variables (such as arrays and objects)
Echo -- output one or more strings
3. templates that can separate HTML and PHP (1 point)
Smarty, Heyes Template Class, etc.
5. what tools are used for version control? (1 point)
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. The question is what tool is used. well, this may need to be answered in this way: CVS Server on Apache serves as the Server, WinCVS serves as the client, and Subversion on Apache/DAV serves as the Server, tortoiseSVN is used as the client, or Subclipse is used as the client.
6. how to implement string flip? (3 points)
Strrev ()
Or
$ Str = "abcdefg ";
Function strrevv ($ str)
{
$ Len = strlen ($ str );
$ Newstr = '';
For ($ I = $ len; $ I >=0; $ I --)
{
$ Newstr. = $ str {$ I };
}
Return $ newstr;
}
$ Showstr = strrevv ($ str );
Echo $ showstr ."
";
---------------------------------------------------------------
7. optimize the MYSQL database. (4 points, more writes)
(1) select the most suitable field attribute and set the field as not null as much as possible. in this way, the database does NOT need to compare NULL values during future query.
(2). use JOIN instead of subquery (Sub-Queries)
(3). use UNION instead of manually created temporary tables
(4). use the LIKE keyword and wildcard as few as possible.
(5). use transactions and foreign keys
Or
(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, slave server read only, or N servers, each machine 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 the required data is obtained from the database, for example, querying the number of comments of an article, select count (*)... where article_id =. do not select *... where article_id = then msql_num_rows. send only required SQL statements. for example, if you modify only the title when modifying an article, update the title... 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.
8. PHP meaning (1 minute)
Hypertext Preprocessor
9. what is the function for MYSQL to obtain the current time ?, The format function is (2 points)
Now (), DATE_FORMAT (date, format)
10. the method for intercepting Chinese strings without garbled characters is implemented. (3 points)
Mb_substr ()
---------------------------------------------------------------
11. have you used version control software? What is the name of the version control software you use? (1 point)
TortoiseSVN-1.2.6 svn-1.2.3
12. have you used the template engine? What is the name of the template engine that you use? (1 point)
Smarty
13. Briefly describe your most proud development work (4 points)
This is what you think, because you are no longer a Cainiao, everyone has different ideas, and their ideas will change with their own knowledge ......
14. What methods do you use to solve the traffic issue for high-traffic websites? (4 points)
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.
-----------------------------------------------------------------
15. use PHP to write the code for displaying the client IP address and server IP Address: 1 point)
// Display client I
Function get_client_ip (){#
If (getenv ('http _ CLIENT_IP ')){
$ Client_ip = getenv ('http _ CLIENT_IP ');
} Elseif (getenv ('http _ X_FORWARDED_FOR ')){
$ Client_ip = getenv ('http _ X_FORWARDED_FOR ');
} Elseif (getenv ('remote _ ADDR ')){
$ Client_ip = getenv ('remote _ ADDR ');
} Else {
$ Client_ip = $ HTTP_SERVER_VAR ['remote _ ADDR '];
}
Return $ client_ip;
}
// Server IP address
Function get_server_ip (){
If (isset ($ _ SERVER ))
{
If ($ _ SERVER ['server _ ADDR ']) $ huoqu_ip = $ _ SERVER ['server _ ADDR'];
Else $ huoqu_ip =$ _ SERVER ['Local _ ADDR '];
}
Else
{
$ Huoqu_ip = getenv ('server _ ADDR ');
}
Return $ huoqu_ip;
}
16. what is the difference between the include statement and require statement? To avoid multiple accesses to the same file (?) Statement instead of them? (2 points)
Require () and include () are identical in all aspects except how to handle failures. Include () generates a warning and require () causes a fatal error.
In other words, if you want to stop processing the page when a file is lost, use require (). This is not the case with include (). The script will continue to run.
Require () will contain files in any way, and include () can selectively include. www.
Replace
Include_once
Require_once
17. how to modify the SESSION survival time (1 point). (no test)
$ SavePath = "./session_save_dir /";
$ LifeTime = 24*3600;
Session_save_path ($ savePath );
Session_set_cookie_params ($ lifeTime );
Session_start ();
18, there is a web address, such as PHPma home: http://www.phpma.com, how to get its content? ($1)
File_get_contents ($ url)
19. in HTTP 1.0, status code 401 means (?); If the message "File Not Found" is returned, the header function is available. The statement is (?); (2 points)
Unauthorized)
Header ("http/1.0 403 Forbidden ");
Classic interview questions (PHP basic II) attached answer Source: edited by this site: phpma Time: Tag: PHP classic interview questions (basic ii) attached answer click: 44 interviews and written examinations are often indispensable for job hunting and recruitment. as a php programmer, more or less will have similar experiences ...... The following are my PHP interview questions collected and sorted out. I hope to help my colleagues and find a suitable php development job! (Three in total)
The following is an interview question (I). The next one is a classic interview question (PHP BASIC III) with an answer that PHP has given:
12. in PHP, heredoc is a special string and its end mark must be? (1 point)
In most languages, double quotation marks are strings and single quotation marks are characters. However, in PHP, there are three forms of string representation. That is:
Single quotes
Double quotation marks
Delimiter (heredoc syntax)
As you can see, single quotes can be used to represent strings. What if I want to express single quotes? Like most languages, use escape characters. That is, the backslash "". what is the difference between using single quotes and double quotes? My point is that there is no big difference. The only difference is that double quotation marks can apply more escape characters.
Let's define the delimiter. Its syntax is "<". It is used to provide an identifier after the identifier, and then provide a string after the identifier, and then provide the identifier after the string to end. For example:
$ Str = <
Hello, this is an example for HEREDOC Syntax.
Please attention to it.
EOD;
Echo $ str;
?> Note that the identifier provided here is EOD, and the string is in the middle.
<
The end mark must be written in the top frame and end with a semicolon.
13. Advantages and disadvantages of asp, php, and jsp (1 point) -- (please search by yourself)
14. about mvc (1 point)
The MVC (Model/View/Controller) mode includes three types of objects. Model is the application object, and View is its representation on the screen,
The Controller defines how the user interface responds to user input.
Model-view-controller (MVC) is a software design pattern which appeared in Smalltalk-80 in 1980s S. It has been widely used now.
1) Model)
A model is the main part of an application. The model indicates business data or business logic.
2) View)
A view is a part of the user interface in an application. it is the interface that the user sees and interacts.
3) controller)
The controller controls the display and update of the model object status of user interface data based on user input.
-------------------------------------------------------------------
15. write the SQL statement for the top 10 people with the most posts. use the following table: members (id, username, posts, pass, email) (2 points)
Select members. username
From members
Order by posts DESC
Limit 10
16. The difference between passing a value in php and transferring a reference. When will the value be passed for reference? (2 points)
Pass by value: any changes to the value within the function range will be ignored outside the function.
Pass by reference: any change to the value within the function range can also reflect the changes to PHPma outside the function.
Advantages and disadvantages: when passing by value, php must copy the value. This is especially costly for large strings and objects.
Transferring by reference does not require copying values, which is good for performance improvement.
17. what is the role of error_reporting in PHP? (1 point)
Used to configure the error message return level
18. write a function to verify that the email format is correct (2 points)
// If the email address is valid, return true, else return false
Function validateEmail ($ email)
{
If (eregi ('^ [_ a-z0-9-] + (. [_ a-z0-9-] +) * @ [a-z0-9-] + (. [a-z0-9-] +) * $ ', $ email )){
Return true;
} Else {
Return false;
}
}
19. briefly describe how to obtain the path of the script to be executed, including the obtained parameters. (2 points)
Echo $ _ SERVER ['script _ filename']. "? ". $ _ SERVER ['query _ string'];
20. how to modify the SESSION survival time (1 point)
Setcookie ()
Or
Session_set_cookie_params ($ lifeTime)
--------------------------------------------------------------------
21. what is the function in the JS form pop-up dialog box? What is the input focus function? (2 points)
Alert (), prompt (), confirm ()
Focus ()
22. what is the JS steering function? How to introduce an external JS file? (2 points)
Window. location. href