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 (2 points) "u % j & q! S $} 0 V8 ~ 4? #?
Date ("Y-m-d H: I: s", strtotime ("-1 days "));

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)

2 W; Q: j * q0 J # t3 K4 \
3. templates that can separate HTML and PHP (1 point)
Smarty, FastTemplate


9 e % q6 S % K9 {3 @ 2 x
4. what tools are used for version control? (1 point)
Svn, csv


5. how to implement string flip? (3 points)
Function newStr ($ str)
{
$ Rs = "";
For ($ I = strlen ($ str); $ I >=0; $ I ++)
$ Rs. = $ str [$ I];
Return $ rs;
}


0 g5] 0 z # \; W + x7 a (
* D3 Z6 f) U3 L U
6. optimize the MYSQL database. (4 points, more writes)
Select the most suitable field attribute
Use JOIN instead of subquery (Sub-Queries)
Use UNION instead of creating a temporary table manually
Transactions
Lock table
Use foreign keys
Use Index
Optimized query statement

7. PHP meaning (1 minute)
PHP, an abbreviated name for nesting, is the abbreviation of "super Text preprocessing language" (PHP: Hypertext Preprocessor ).


F + @ 5 n'e: G-Y; B "B


8. what is the function for MYSQL to obtain the current time ?, The format function is (2 points)
Now ();
Date_format ();


9. the method of intercepting Chinese strings without garbled characters is implemented. (3 points) $ \ '% B1 r6 c6 H4 B "I5 O/V
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;
}
}


10. have you used version control software? What is the name of the version control software you use? (1 point)
Svn


; X8 K5 M & Z * [/V/v
11. have you used the template engine? What is the name of the template engine that you use? (1 point)
Smarty


12. Briefly describe your most proud development work (4 points)


4 q; O # e] 8 w * B :{
13. 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.

O1 j. H'' & M
14. use PHP to write the code for displaying the client IP address and server IP Address: 1 point)
Server ip: echo $ _ SERVER ['http _ host']
Client IP: echo $ _ SERVER ['remote _ ADDR ']

) P # @ * r % P # G8 ~ * Y + {"|) [2 R
15. 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)
When an exception occurs, include generates a warning. require generates a fatal error.
Contains only one include_once, require_once

16. how to modify the SESSION survival time (1 point ).
Session_set_cookie_params (survival seconds );
Setcookie ();

17. there is a webpage address, such as the homepage of the PHP Research Office: http://www.phpv.net/index.html. how can I find my website content? ($1)
File_get_contents ($ url)

18. in HTTP 1.0, status code 401 indicates (?); If the message "File Not Found" is returned, the header function is available. The statement is (?); (2 points)
401 Unauthorized access to Unauthorized;
Header ('http/1.1 404 Not Found ');

: X5 n; A: U + L7 [g; c
19. in PHP, heredoc is a special string and its end mark must be? (1 point)
Must be the top level.

20. Advantages and disadvantages of asp, php, and jsp (1 point)


-X6 v8! S *}.?
21. 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.

''7 @ 6 U (G0? & J $ J6 n
22. 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 username FROM members order by posts desc limit 10


23. The difference between passing a value in php and transferring a reference. When will the value be passed for reference? (2 points)
Transferring a value is a copy of a value in the stack, and transferring a reference is a copy of a symbol pointing to a value in the stack. If the original value is changed and the reference is passed, the value is passed without any change.

24. what is the role of error_reporting in PHP? (1 point)
Set the error message return level

25. please write a function to verify that the email format is correct (2 points)
Function validateEmail ($ email)
{
Return ereg ('^ [-_ \. a-zA-Z0-9] + @ [-a-zA-Z0-9] + \. [-\. a-zA-Z0-9] + $', $ email );
}


;] * M'f + _ 0 I. '& r3 P6 r4 G
26. briefly describe how to obtain the path of the script to be executed, including the obtained parameters. (2 points)
Echo $ _ SERVEpastingR ['script _ filename']. "? ". $ _ SERVER ['query _ string'];


27. how to modify the SESSION survival time (1 point)
Setcookie ();


28. what is the function in the JS form pop-up dialog box? What is the input focus function? (2 points)
Alert (); prompt (); confirm ();
Focus ();


# H & g % k M0 G $ s/E /~ 5 C "l/u + M
29. what is the JS steering function? How to introduce an external JS file? (2 points)
Window. location = "";

30. what is the difference between foo () and @ foo? (1 point )! S) x1 q # G * F1 t: F
@ Can block errors!

31. how to declare a class named "myclass" without methods and attributes? (1 point)
Class myclass {};

6 N: I B. M. w3 X/s4 t $ s
32. how to instantiate an object named "myclass? (1 point)
$ NewClass = new myclass ();


33. how do you access and set attributes of a class? (2 points)
$ Test = new myclass ();
$ Test-> oneParam = "test ";
Echo $ test-> twoParam;


34. what is the difference between mysql_fetch_row () and mysql_fetch_array? (1 point) 5 X # w + V, g2 B
Mysql_fetch_row -- obtains a row from the result set as an enumerated array
Mysql_fetch_array -- get a row from the result set as an associated array, or a number array, or both

35. what is the GD library used? (1 point)
The GD Library provides a series of APIs for processing images. you can use the GD library to process images or generate images.
The GD library on a website is usually used to generate thumbnails, add watermarks to images, or generate reports for website data.

36. point out some methods to input a piece of HTML code in PHP. (1 point), U $ o # n3 B)]; S "P/G
Print ("
");
Echo"
";

37. Which of the following functions can open a file to read and write the file? (1 point)
Select c
(A) fget () (B) file_open () (c) fopen () (d) open_file ()

38. Which of the following options does not add john to the users array? (1 point)
Select B, c, and d, where B is a function that does not exist.
(A) $ users [] = 'John ';
(B) array_add ($ users, 'John'); $ y0 B # B9 _ l: L
(C) array_push ($ users, 'John ');
(D) $ users | = 'John ';


* Z4 g4 s: Q. q6 |/a & K & l
39. Will the following program enter? (1 point); | 1 H (p! ~ #~ $ | 7 K0 x
$ Num = 10; 8 L: @ % v/T4 U6? 1 [
Function multiply () {9] $ g! V I + O ++ _: U5 ^ "E-h-C
$ Num = $ num * 10;
}
Multiply ();-Q + y/^ $ O2 X6 | 4 h
Echo $ num; * y6 l8 x-x % K. \ % H % s5 p
?>
No, local variable #~ & J6 Q3 k $ {("']


40. use php to write a simple query, find all the content named "zhang san", and print it out (2 points) 5 t3 H0 r-J (P
Table name UserName Tel Content Date't :? 2 '$ B; C4'
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
Complete the code according to the above question:
$ Mysql_db = mysql_connect ("local", "root", "pass ");
@ Mysql_select_db ("DB", $ mysql_db );

$ Result = mysql_query ("select * from User where Name = 'Zhang San '");
While ($ row = mysql_fetch_array ($ result ))
{
Echo $ row ['name']. $ row ['tel']. $ row ['content']. $ row ['Date'];
Echo"
";
}

41. how to use the following classes and explain what the following means? (3) 2 L + r1 z n) s, S ~. X
Class test {
Function Get_test ($ num) {$ x; b9 r7 v3 X & c # q $ s & c 'a0 I
$ Num = md5 (md5 ($ num). "En ");
Return $ num;
}
}
Double md5 encryption
/G :~ 8 [# u3] # G) W. B


42. write SQL statement format: INSERT, UPDATE, delete (4 points) L & C5 m-_ 0 Q (s0 Q-K9 Q
Table name UserName 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
(A) there is a new record (Mr. Wang graduated from high school 13254748547-). please use SQL statements to add it to the table.
Insert into User ('name', 'tel', 'content', 'date') VALUES ('Wang ', '123456', 'High School Graduation ', '2017-2007 ')
E6 v "Q; z-m3 B + A ('2}
(B) use SQL statements to update Michael's time to the current system time.
UPDATE User SET Date = DATE_FORMAT (NOW (), '% Y-% m-% d') WHERE Name = 'Zhang san'
(C) please write out all records named zhangsi.
Delete from User WHERE Name = 'zhangsi'


43. enter the meaning of the data type (int char varchar datetime text). What is the difference between varchar and char (2 points)
Int value type char fixed length string varchar variable length string datetime text character string
The length of the char column is fixed to the length declared during table creation. The value in the varchar column is a variable length string.

44. the MySQ auto-increment type (usually the table ID field) must be set (?) Field (1 point)
PrimaryKey, AUTO_INCREMENT

45. write the output result of the following program (1 point) "'(Q6 @ % r/z
$ B = 201;/Y1 z8 s (e! Z & D8 U * \. Y) x1 J
$ C = 40;
$ A = $ B> $ c? 4: 5; ^ 4 n4 I: X-B's
Echo $;
?>
Result: 4


46. check whether a variable has a set function? Is it a null function? (2 points) 3 X & I & m2 R "c # H $ S & g1 W
Isset () empty ()

* Y0 l: p-e & t4 w) I "U
47. what is the function used to obtain the total number of query result sets? (1 point)
Count ()


48. $ arr = array ('James ', 'Tom', 'symfony '); print the value of the first element (1 point) (k7 c4 S:])] # I
Echo $ arr [0];


49. use the ',' to separate the array values of the 48 questions and combine them into strings for output (1 point)
$ Arr1 = implode (",", $ arr );

* C3 Q3 n) | 5 I. f "c) | + p8 S; P
50, $ a = 'abcdef '; please take out the value of $ a and print the first letter (1 point)
Echo $ a [0];
Echo substr ($ a, 0, 1)


51. can PHP be connected to databases such as SQL server and oracle? (1 point)
Yes


8] 7 c.}-f5 l "o * W? 0 I0?
52. write the PHP5 permission control modifier (3 points)
Private protected public

/X2 ?. E) F/d
53. write the php5 constructor and Destructor (2 points)
_ Construct _ destruct

"{/E + C1 p # o5 D-^
54. use PHPMYADMIN to complete the following steps:
(1) create a news publishing system. The Table named message has the following fields (3 points)/z) Q (g0 G7 K. w $ r-c & _ 8 y + y5 q3 F
Id Article id:} 5 |: G0 L! S4 i9 F & T3 h $ V2 _
Title article title 6 M + w1 P4 F; Y % _ 0 ^
Content
Category_id document Category id
Hits clicks

7 k $ z.} 9 W $ x; w1 ~ 9 |
(2) Similarly, the above-mentioned news publishing system: the table comment records the user's reply content. The fields are as follows (4 points) 9 U # K-X O8 p1 j6 m9 n
Comment_id reply id-W-M "]: [& a 'F & D-Y-B
Id document id, associated with the id in the message Table
Comment_content reply content 7 n/J, l % k6 W (A. {+ f-r
To query the database, you need to obtain a list of article titles in the following format and sort them by the number of replies. The highest number of replies is listed at the top: [, [-^ 9 X % j6 f *? & D,]
Article id: number of replies in the document title
Use an SQL statement to complete the above query. if the article does not reply, the number of replies is displayed as 0.
SELECT message. id, message. title IF (message. hit is NULL, 0, message. hit) hits,
IF (comment. id, 0, count (*) number
FROM message
LEFT JOIN
Comment ON comment. id = message. id
Group by message. id

(3) in the preceding content management system, the table category stores the category information. The fields are as follows (3 points)
Category_id int (4) not null auto_increment; "_ 3 r-r'r) Y & \ $ W
Categroy_name varchar (40) not null;
When you enter an article, select an article category from the drop-down menu, E "K * Y9 _ % M7 Z1 M; h
Write down how to implement this drop-down menu


Blank question
1. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable $ _ SERVER ["PHP_SELF; the URL that is linked to the current page is recorded in the predefined variable $ _ SERVER ["HTTP_REFERER.
2. Execution section 0 is output. 'B8 o & W % j d: H % c5 q
3. in HTTP 1.0, status code 401 indicates that it is not authorized. if the "File Not Found" prompt is returned, the header function is available, the statement is header (HTTP/1.0 404 Not Found ).
4. the array function arsort is used to sort the array in reverse order and maintain the index relationship. The role of the statement error_reporting (2047) is All errors and warnings. 6g + o' o! F % e
5. the database connection string format in PEAR is "mysql: // root: 123@192.168.0.1/testdb (phptype: // username: password @ protocol + hostspec/database )".
6. write a regular expression and overwrite all JS/VBS scripts on the webpage (that is, remove the scr ī pt mark and its content ):"/ ]. *?>. *? <\/Script>/si ".
7. install PHP using the Apache module in the http. in conf, use the statement LoadModule php5_module "D: \ xampp \ apache \ bin \ php5apache2. dll "dynamically loads the PHP module, and then uses the statement AddType application/x-httpd-source. phps AddType application/x-httpd. php. php3. php4. php5. phtml enables Apache to process all files with the extension of php as PHP scripts.
8. both the include and require statements can include another file to the current file. The difference between them is that include generates a warning and require produces a fatal error. to avoid multiple inclusion of the same file, you can use the statements include_once () and request_once () to replace them.
9. attributes of the class can be serialized and saved to the session, so that the entire class can be restored later. the Function used is serialize ()/unserialize (). 5 M]-V # q. j \ 8 h
10. a function parameter cannot be a reference to a variable unless allow_call_time_pass_reference is set to on.; ^-Q U2 b6? in php. ini ?; F3 \; g
11. in SQL, LEFT JOIN indicates a natural LEFT outer JOIN. If tbl_user records the student's name and student ID, tbl_score records the student's student ID (ID) (which is not recorded after some students take the test) to print the name of each student 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.
12. in PHP, heredoc is a special string whose end mark must end the row of the identifier and cannot contain any other characters ";".


. D9 T /'! F "J4 |; V. k + f
Programming question 2} 9 Z0 g: U! Z6 T2 O
$ X: f & g} 1 y + k6 R) k7 g7 W, T
1. write a function to get the file extension $ n + m7 from a standard url as efficiently as possible? & K. ^/^ 8
Example: http://www.sina.com.cn/abc/de/fg.php? Id = 1 need to retrieve php or. php7 ~ "T3 M5}, W
2. in HTML, the meta tag in the page header can be used to output the file encoding format. The following is a standard meta statement.
Use PHP to write a function and change the value of charset in a standard HTML page similar to meta tag to big57 ~. H * O; P % q ++ ~ : G}
Note:
1. you need to process the complete html page, that is, not only the meta statement 4 T # L/v7 u7 L, k
2. case insensitive
3. 'and "are interchangeable here
4. the quotation marks on both sides of 'content-type' can be ignored, but the quotation marks on both sides of 'text/html; charset = gbk' cannot "O5 L6 v * P! F r! W, u
5. handle extra spaces
3. write a function to calculate the relative path of the two files.
For example, $ a = '/a/B/c/d/e. php ';
$ B = '/a/B/12/34/c. php'; 8 Q-j-B. E/m (m1 D
The relative path of $ B relative to $ a should be http://www.cnblogs.com/c/dadd ()
3. write a function to traverse all files and subfolders in a folder. * T4 ^. B/k'q $ G5 l4 P! {$ G
4. briefly describe the implementation principles of unlimited classification in the forum.

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.