PHP classic interview questions and php classic questions

Source: Internet
Author: User
Tags image processing library

PHP classic interview questions and php classic questions

This article analyzes in detail the typical PHP interview questions. Share it with you for your reference. The details are as follows:

I did some php questions on the Internet, but I don't know how to do it now... I posted the answer for your reference.

1. Use PHP to print the time format of the previous day in the format of 22:21:21 (2 points)

$a = date("Y-m-d H:i:s", strtotime("-1 day"));print_r($a);

2. Differences between echo (), print (), and print_r () (3 points)
Echo and print are not a function, but a language structure.
Int print (string $ arg), with only one parameter
Echo arg1, arg2; multiple parameters can be output and void is returned.
Echo and print can only print the string, but cannot print the structure
Print_r can print the structure
For example

$arr = array("key"=>"value");print_r($arr);

3. templates that can separate HTML and PHP (1 point)
Smarty, phplib

4. What tools are used for version control? (1 point)
Svn, git, cvs

5. How to Implement string flip? (3 points)
English:
Strrev ($)
Chinese or other words:
Chinese: GB2312. The Code uses GB2312 encoding.

<? Php function reverse ($ str) {$ ret = ""; len = mbstrwidth (str, "GB2312"); for (I = 0; I <len; I ++) {arr [] = mbsubstr (str, $ I, 1, "GB2312");} return implode ("", array_reverse ($ arr ));} print_r (reverse ("hello "));

6. Optimize the MYSQL database. (4 points, more writes)
Statement:
1. Use indexes to increase query efficiency
2. Optimize Query statements to Improve Index hit rate
Database:
1. Construct database/table sharding to improve database storage and scalability
2. Use different storage engines as needed

7. PHP meaning (1 minute)
Super Text preprocessing Language
Hypertext PreProcessor

8. What is the function for MYSQL to obtain the current time ?, The format function is (2 points)

CURRENT_TIMESTAMP()DATE_FORMAT()select DATE_FORMAT("2011-11-21 10:10:10", "%Y-%m-%d");

9. The method of intercepting Chinese strings without garbled characters is implemented. (3 points)

mb_substr($str, 1, 1, "GB2312");

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

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)
XXX

13. What methods do you use to solve the traffic issue for high-traffic websites? (4 points)
1. effectively use the cache to increase the cache hit rate
2. Use Server Load balancer
3. Use CDN to store and accelerate static files
4. Reduce database usage
5. Check where the statistical bottleneck is.

14. Use PHP to write the code for displaying the Client IP address and Server IP Address: 1 point)
$ _ SERVER ["REMOTE_ADDR"]
$ _ SERVER ["SERVER_ADDR"]

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)
In case of failure:
Include generates a warning, while require directly produces an error interrupt.
Require load before running
Include load at runtime
Require_once
Include_once

16. How to modify the SESSION survival time (1 point ).
Session_set_cookie_params

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

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)
Unauthorized

header("HTTP/1.0 404 Not Found");

Fast CGI:

header("Status: 404 Not Found");

19. In PHP, heredoc is a special string and its end mark must be? (1 point)
Appear in pairs

$a = <<EODgood testEOD;

20. Advantages and Disadvantages of asp, php, and jsp (1 point)
Asp depends on IIS and is a language developed by Microsoft.
Php and jsp can depend on apache, nginx, and other servers.

21. About mvc (1 point)
Model: Data Structure Layer
View: Display
Control: receives and judges the processing input.

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 top 10 id, username from members order by posts desc

23. The difference between passing a value in php and transferring a reference. When will the value be passed for reference? (2 points)
& Indicates transferring reference
The parameter will be changed when the parameter is passed for reference in the function.
Generally, when multiple output parameters exist, you can consider using references.

24. What is the role of error_reporting in PHP? (1 point)
Set the display level of the error

25. Please write a function to verify that the email format is correct (2 points)

$ Str = "jianfeng@126.com"; regex = "([a −z0 −9 \. −] +) @ ([\ da −z \. −] + )\. ([a −z \.] 2, 6) "; // regular return preg_match (regex, str)

26. Briefly describe how to obtain the path of the script to be executed, including the obtained parameters. (2 points)
$ Argc -- get the number of parameters
$ Argv -- get the parameter list

27. How to modify the SESSION survival time (1 point)
Session_set_cookie_params

28. What is the function in the JS form pop-up dialog box? What is the input focus function? (2 points)

Alert ()
Confirm ()
Promopt ()
Focus ()
 

29. What is the JS steering function? How to introduce an external JS file? (2 points)

window.location.href="#"<script src="#"></script>

30. What is the difference between foo () and @ foo? (1 point)
@ Indicates all warnings are ignored.
 

31. How to declare a class named "myclass" without methods and attributes? (1 point)

class myclass{}

32. How to instantiate an object named "myclass? (1 point)

$myclass = new myclass();

33. How do you access and set attributes of a class? (2 points)

<?phpclass A{ public $name = "A";}$a = new A();n=a->name;print_r($n);

34. What is the difference between mysql_fetch_row () and mysql_fetch_array? (1 point)
Mysql_fetch_array () is an extension of mysql_fetch_row. In addition to storing data in an array as a digital index, you can also store data as an associated index and use the field name as the key name.

<?phpmysql_connect("localhost", "mysql_user", "mysql_password") ordie("Could not connect: " . mysql_error());mysql_select_db("mydb");$result = mysql_query("SELECT id, name FROM mytable");while (row=mysqlfetcharray(result, MYSQL_ASSOC)) {printf ("ID: %s Name: %s", row["id"],row["name"]);}mysql_free_result($result);

35. What is the GD library used? (1 point)

Dynamic Open image processing Library

36. Point out some methods to input a piece of HTML code in PHP. (1 point)

echo "{html}"echo <<EOD{html}EOD;

37. Which of the following functions can open a file to read and write the file? (1 point) 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) B
(A) $ users [] = 'john ';
(B) array_add ($ users, 'john ');
(C) array_push ($ users, 'john ');
(D) $ users | = 'john ';

39. Will the following program enter? (1 point) 10

$num = 10;function multiply(){num=num * 10;}multiply();echo $num;?>

40. Use php to write a simple query, find all the content named "Zhang San" and print it out (2 points)
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
Complete the code according to the above question:

$ Mysql_db = mysql_connect ("local", "root", "pass"); @ mysql_select_db ("DB", $ mysql_db ); $ SQL = sprintf ("select * from % s where UserName = '% S'", "table name", "Zhang San"); values = mysqlquery (SQL ); while (item = mysqlfetchqueryarray (values) {echo sprintf ("username: % s, Tel. % s, education: % s, graduation date: % s ", item ['username'], item ['tel'], item ['content'], item ['date']);}

41. How to use the following classes and explain what the following means? (3)

class test{function Get_test($num){num=md5(md5(num)."En");return $num;}}$test = new test();ret=test->Get_test(11);print_r($ret);exit;

Associate the 32-bit a1 string generated after the MD5 encoding of num with "En" and then perform the MD5 encoding again.

42. Format of writing SQL statements: insert, update, and delete (4 points)
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 table name values ('wang ', '123', 'high school graduation', '2017 ')
(B) use SQL statements to update Michael's time to the current system time.
Update table name set Date = GETDATE () where UserName = "zhangsan"
(C) Please write out all records named zhangsi.
Delete from indicates where UserName = "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 integer
Char Storage Duration
Varchar storage becomes longer
Datetime time
Text storage extended
Varchar Variable Length
Char (20) Fixed Length

44. The MySQ auto-increment type (usually the table ID field) must be set (?) Field (1 point)
Auto_increment
45. Write the output results of the following Program (1 point)

$b=201;$c=40;a=b>$c?4:5;echo $a;

46. check whether a variable has a set function? Is it a null function? (2 points)
Isset ()
Empty ()
 

47. What is the function used to obtain the total number of query result sets? (1 point)

mysql_num_rows()

48. $ arr = array ('James ', 'Tom', 'symfony '); print the value of the first element (1 point)

print_r($arr[0]);reset($arr);print_r(current($arr));print_r(array_shift($arr));

49. Use the ',' to separate the array values of Question 41 and combine them into strings for output (1 point)
Implode

50. a = 'abcdef'; extract the value of a and print the first letter (1 point)

$a[0];substr($a, 0, 1);

51. Can PHP be connected to databases such as SQL server and oracle? (1 point)
Yes
There are ready-made Libraries

52. Write the PHP5 permission control modifier (3 points)
Public
Private
Protected

53. Write the php5 constructor and destructor (2 points)

public function __construct(){}public function __destruct(){}

Programming questions:

1. Write a function to retrieve the file extension from a standard url as efficiently as possible.
Example: http://www.sina.com.cn/abc/de/fg.php? Id = 1 need to retrieve php or. php

<?php$url = "http://www.sina.com.cn/abc/de/fg.php?id=1";arr=parseurl(url);pathArr=pathinfo(arr['path']);print_r($pathArr['extension']);

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 ';
The relative path of B relative to a should be http://www.bkjia.com/12/34/c.php.

<? Php $ a = '/a/B/c/d/e. php '; $ B ='/a/B/12/34/c. php'; // obtain the relative path of the path to conpath function sGetRelativePath (path, conpath) {pathArr = explode ("/", path); conpathArr = explode ("/", conpath); $ dismatchlen = 0; for (I = 0; I <count (pathArr); I ++) {if (conpathArr [I]! = PathArr [I]) {dismatchlen = count (pathArr)-$ I; arrLeft = arrayslice (pathArr, $ I); break ;}} ret = strrepeat (".. /", dismatchlen ). implode ("/", $ arrLeft); return $ ret;} print_r (sGetRelativePath (B, ));

3. Write a function to traverse all files and subfolders in a folder.

<? Phpfunction aGetAllFile ($ folder) {$ aFileArr = array (); if (is_dir ($ folder) {handle = opendir (folder ); while (file = readdir (handle ))! = False) {// If yes. or .. skip if (file = ". "| file = ".. ") {continue;} if (is_file (folder. "/". file) {aFileArr [] = file;} else if (is_dir (folder. "/". file) {aFileArr [file] = aGetAllFile (folder. "/". file) ;}} closedir ($ handle);} return $ aFileArr;} $ path = "/home/test/SQL"; print_r (aGetAllFile ($ path ));

I hope this article will help you with php programming.

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.