In our previous course, we introduced PHP interview questions about thinkphp, as well as 2017 of the most comprehensive PHP interview questions and answers summary, many of the PHP interview questions are oral, there are many written questions of the PHP interview, today we will give you to summarize!
The written test in the PHP interview question
1. Write code that displays client IP and server IP in PHP
Answer: Print Client
Ip:echo $_server[' remote_addr '];
Or:
getenv (' remote_addr ');
Print server IP:
echo gethostbyname (' www.meizhi520.com ')
What is the difference between 2.session and cookie?
A: Session: Store user access to the global unique variable, stored in the server PHP specified directory (session_dir) in the location of the store cookie: used to store a page in a continuous use, is stored in the client, For a cookie, it is stored in the user win's temp directory. Both can be set time by time
3. What is the difference between get and post submission methods in a form?
A: Get is a send request HTTP protocol to receive via URL parameter delivery, while post is entity data that can be submitted with a large amount of information through a form.
4. The time format for printing the previous day in PHP is 2013-11-26 12:11:11
For:
Echodate (' y-m-d h:i:s ', Strtotime ('-1 days '));
5. Write a function that can traverse all the files and subfolders under a folder. (Directory operations)
$d = Dir (dirname (__file__)); echo "Handle:". $d->handle. "\ n"; echo "Path:". $d->path. "\ n", while (false!== ($entry = $d->read ())) {echo $entry. "";} $d->close ();
6. Please write a function to verify that the e-mail message is properly formatted
function Checkemail ($email) {$pregEmail = "/([a-z0-9]*[-_\.]? [a-z0-9]+] *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\.] [A-z] {2,3} ([\.] [A-z] {2})? /i "; return Preg_match ($pregEmail, $email);}
7. The implementation of the text string interception without garbled method.
function Gbsubstr ($string, $start, $length) { if (strlen ($string) > $length) { $str =null; $len = $start + $length; for ($i = $start; $i < $len; $i + +) { if (Ord (substr ($string, $i, 1)) >0xa0) { $str. =substr ($string, $i, 2); $i + +; } else{ $str. =substr ($string, $i, 1); } } return $str. ' ... '; } else{ return $string; }}
What is the 8.JS steering function? How to introduce an external JS file?
Window.location.href <script type= "Text/javascript" src= "Js/js_function.js" ></script>
9.MySQL database, how to optimize?
Answer: (1) configuration optimization (server configuration)
(2) Build table optimization (table, field settings)
(3) query optimization (SQL statement)
A: 1, select the most applicable field properties, to minimize the definition of field length, as far as possible to set the field not NULL, such as ' Province, gender ', preferably set to enum
2. Use connection (join) instead of subquery:
3. Use Union (Union) instead of manually created temporary table
4. Transaction processing:
5, lock the table, optimize transaction processing:
6, using foreign keys, optimize the locking table
7. Build the index:
8. Optimizing Query Statements
10. How to use the following class and explain what the following means?
Class test{ function Get_test ($num) { $num =md5 (MD5 ($num). En "); return $num; }}
For:
$testnum = "123″; $object = new test (); $encrypt = $object->get_test ($testnum); Echo $encrypt;
The class test contains the Get_test method, instantiating the class invocation method, multi-string encryption
Summarize:
Here we just summed up a bit, in the PHP interview problem will often meet the pen test, we can refer to this, you can also expand, enhance their knowledge points! Hope to help you!
Related recommendations:
2017 Most complete PHP interview questions and Answers summary
Summary of thinkphp Topics in PHP interview questions
2017 recruitment season: PHP Surface test Questions Super Strong summary!