Home  >  Article  >  Backend Development  >  PHP classic interview questions (Basic Type I) with answers_PHP tutorial

PHP classic interview questions (Basic Type I) with answers_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:10:14842browse

Job hunting and recruitment often require interviews and written tests. As a PHP programmer, you will have more or less similar experiences... The following are PHP interview questions that I have collected and organized. I hope it will be helpful to my peers and find a job. The right php development job! (Three sections in total)

The following are interview questions (1)

1. Use PHP to print out the time of the previous day in the format of 2009-02-10 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. The difference between echo(), print() and print_r() (3 points)

echo is a PHP statement, print and print_r are functions, statements have no return value, and functions can have return values ​​(even if they are useless)

print can only print out the values ​​of simple type variables (such as int, string)

print_r can print out the value of complex type variables (such as arrays, objects)

echo -- output one or more strings

3. A template that allows HTML and PHP to be used separately (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, but CVS is an old brand with a high market share. I have always used SVN, and the question is asking what tool to use. Well, this may need to be answered like this: CVS Server on Apache As the server, WinCVS as the client; Subversion on Apache/DAV as the server, TortoiseSVN as the client, or Subclipse as the client.

6. How to implement string flipping? (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. Methods to optimize MYSQL database. (4 points, write more and get more)

(1). Select the most applicable field attribute and try to set the field to NOT NULL, so that the database does not need to compare NULL values ​​when executing queries in the future.

(2). Use connection (JOIN) instead of sub-query (Sub-Queries)

(3). Use UNION to replace manually created temporary tables

(4). Use LIKE keywords and wildcards as little as possible

(5).Use transactions and foreign keys

or

(1). In terms of database design, this is the responsibility of the DBA and Architect. Design a well-structured database. When necessary, denormalize it (English is this: denormalize, I don’t know the Chinese translation), allowing some Data redundancy, avoid JOIN operations to improve query efficiency

(2). In terms of system architecture design, table hashing is used to hash massive data into several different tables. Fast and slow tables, the fast table only retains the latest data, and the slow table is a historical archive. Cluster, main server Read & write, read only from the server, or N servers, each machine is the Master of each other

(3). (1) and (2) exceed the requirements of PHP Programmer, it will be better, it doesn’t matter. Check whether there are less indexes

(4). Write efficient SQL statements and see if there are any inefficient SQL statements, such as full joins that generate Cartesian products, a large number of Group By and order by, no limit, etc. when necessary. , encapsulate the database logic into the stored procedure on the DBMS side. Cache the query results and explain each SQL statement

(5). Everything you get is required. Only get the necessary data from the database. For example, to query the number of comments on an article, select count(*) ... where article_id = is enough. Do not select * first ... where article_id = then msql_num_rows. Only transmit the necessary SQL statements. For example, when modifying an article, if the user only modifies the title, then 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 query speed by an order of magnitude

8. What does PHP mean (get 1 point)

Hypertext Preprocessor

9. What is the function of MYSQL to obtain the current time?, and the function of formatting date is (2 points)

now(), DATE_FORMAT(date,format)

10. A method to intercept Chinese text strings without garbled characters. (3 points)

mb_substr()

-------------------------------------------------- ----------------

11. Have you ever used version control software? If so, what is the name of the version control software you used? (1 point)

TortoiseSVN-1.2.6 svn-1.2.3

12. Have you ever used a template engine? If so, what is the name of the template engine you used? (1 point)

smarty

13. Please briefly describe your most proud development work (4 points)

Think about this yourself, because you are no longer a rookie. Everyone has different ideas, and their ideas will change with their own knowledge...

14. For websites with large traffic, what methods do you use to solve the traffic problem? (4 points)

First, confirm whether the server hardware is sufficient to support the current traffic

Secondly, optimize database access.

Third, external hotlinking is prohibited.

Fourth, control the download of large files.

Fifth, use different hosts to divert main traffic

Sixth, use traffic analysis and statistics software.

-------------------------------------------------- ------------------

15. Use PHP to write the code to display the client IP and server IP 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

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 and require statements? To avoid including the same file multiple times, you can replace them with (?) statements? (2 points)

require() and include() are identical in every aspect except how to handle failure. include() produces a warning and require() causes a fatal error.

In other words, if you want to stop processing the page when a file is missing, use require(). This is not the case with include() and the script will continue to run.

require() will include the file anyway, while include() can optionally include .www.

Use

instead of

include_once

require_once

17. How to modify the survival time of SESSION (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 page address, such as PHPma homepage: http://www.phpma.com, how to get its content? ($1 point)

file_get_contents($url)

19. In HTTP 1.0, the meaning of status code 401 is (?); if the prompt "File not found" is returned, the header function can be used, and its statement is (?); (2 points)

Unauthorized

Header("http/1.0 403 Forbidden");

Classic interview questions (PHP basic type II) with answers Source: Editor of this site: phpma Time: 2009-02-13 Tag: PHP Classic interview questions (PHP basic type II) with answers Clicks: 44 Job hunting and recruitment are often indispensable Interviews and written tests, as a PHP programmer, you will have more or less similar experiences... The following are PHP interview questions that I have collected and organized. I hope it will be helpful to my peers and find a suitable PHP development job! (Three sections in total)

The following are interview questions (1), next article: Classic interview questions (PHP Basic Type III) with answers. PHP has given answers:

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

In most languages, double quotes are strings and single quotes are characters. But in PHP, there are three representations of strings. That is:

Single quotes

Double quotes

Delimiter (heredoc syntax)

See, single quotes can actually be used to represent strings. So what if I want to represent single quotes? As with most languages, use escape symbols. That is, backslash "". So what is the difference between using single quotes and double quotes? My point is there isn't much difference. The only difference is that double quotes can apply more escape characters.

Let’s delimit it. Its syntax is "<<<". Usage is to provide an identifier after it, then a string after the identifier, and then provide this identifier after the string to end. For example:

$str = <<

Hello, this is an example for HEREDOC Syntax.

Please pay attention to it.

EOD;

echo $str;

?> Note that the identifier provided here is EOD, and the middle one is a string.

<<

The end mark must be written in a top-case format and must end with a semicolon

13. Talk about the advantages and disadvantages of asp, php and jsp (1 point) - (please search for details)

14. Talk about your understanding of mvc (1 point)

MVC (Model/View/Controller) pattern includes three types of objects. Model is the application object, View is its representation on the screen,

Controller defines how the user interface responds to user input.

Model-View-Controller (MVC) is a software design pattern that appeared in Smalltalk-80 in the 1980s and is now widely used.

1) Model

The model is the main body of the application. Model represents business data, or business logic.

2) View

View is the user interface-related part of the application, the interface that users see and interact with.

3) Controller

The controller's job is to control the user interface data display and update the model object state based on the user's input.

-------------------------------------------------- ------------------

15. Write the SQL of the names of the ten people with the most posts, using the following table: members (id, username, posts, pass, email) (2 points)

select members.username

from members

order by posts DESC

limit 10

16. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference? (2 points)

Pass by value: Any changes to the value within the scope of the function will be ignored outside the function

Pass by reference: Any changes to the value within the scope of the function will also reflect these modifications outside the function PHPma

Pros and Cons: When passing by value, php must copy the value. Especially for large strings and objects, this can be a costly operation.

Passing by reference does not require copying the value, which is very good for improving performance.

17. What is the function of error_reporting in PHP? (1 point)

Used to configure the level of error message reporting

18. Please write a function to verify whether the format of the email 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 get the current execution script path, including the obtained parameters. (2 points)

echo $_SERVER['SCRIPT_FILENAME']."?".$_SERVER['QUERY_STRING'];

20. How to modify the survival time of SESSION. (1 point)

setcookie()

or

session_set_cookie_params($lifeTime)

-------------------------------------------------- --------------------------

21. What is the function to pop up a dialog box in a JS form? What is the function to get input focus? (2 points)

alert(),prompt(),confirm()

focus()

22. What is the redirect function of JS? How to introduce an external JS file? (2 points)

window.location.href

23. What is the difference between foo() and @foo()? (1 point)

PHP supports an error control operator: @. When placed before a PHP expression, any error message that expression may produce is ignored.

Note: The @ operator is only valid for expressions. A simple rule for beginners is: if you can get a value from somewhere, prepend it with the @ operator. For example, you can put it before variables, functions and include() calls, constants, etc. It cannot be placed before the definition of a function or class, nor can it be used in conditional structures such as if and foreach.

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

class myclass{};

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

$newmyclass = new myclass();

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

Pass->

$newmyclass = new myclass();

$temp=$newmyclass->testvalue;

$newmyclass->testvalue="a";

27. What is the difference between mysql_fetch_row() and mysql_fetch_array? (1 point)

mysql_fetch_row -- Get a row from the result set as an enumeration array

mysql_fetch_array -- Fetch a row from the result set as an associative array, a numeric array, or both

-------------------------------------------------- --------------------------

28. What is the GD library used for? (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.

On websites, the GD library is usually used to generate thumbnails or to add watermarks to images or to generate reports on website data.

29. Point out some ways to enter a piece of HTML code in PHP. (1 point)

print("
");

echo "
";

30. Which of the following functions can open a file for reading and writing? (1 point)(c)

(a) fget() (b) file_open() (c) fopen() (d) open_file()

31. Which of the following options does not add john to the users array? (1 point) (b)(c)(d)

(a) $users[] = ‘john’;

(b) array_add($users,’john’);//Not sure about this option, but there is no such function in the test

(c) array_push($users,‘john’);

(d) $users ||= ‘john’;

32. Will the following program be input? (1 point)

$num = 10;

function multiply(){

$num = $num * 10;

}

multiply();

echo $num;

?>

No, local variable

33. Use PHP to write a simple query to find out all the content named "Zhang San" and print it out (2 points)

Table name User

Name Tel Content Date

Zhang San 13333663366 Graduated from college 2006-10-11

Zhang San 13612312331 Bachelor degree 2006-10-15

Zhang Si 021-55665566 Graduated from technical secondary school 2006-10-15

Please 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 "
";

}

34. How to use the following classes and explain what they mean? (3)

class test{

function Get_test($num){

$num=md5(md5($num)."En");

return $num;

}

}

Double md5 encryption

$testObject = new test();

$encryption = $testObject->Get_test("xiaotian_ls");

Classic interview questions (PHP basic type III) PHP Source: Editor of this site: phpma Time: 2009-02-13 Tag: Classic interview questions (PHP basic type III) PHP Clicks: 31 Job hunting and recruitment are often indispensable for interviews and Written test, as a PHP programmer, I will have more or less similar experiences... The following are PHP interview questions that I have collected and organized. I hope it will be helpful to my peers and find a suitable PHP development job! (Three sections in total)

The following are classic interview questions (PHP Basic Type III) with answers. PHP has given answers:

35. Write the format of SQL statements: insert, update, delete (4 points)

Table name User

Name Tel Content Date

Zhang San 13333663366 Graduated from college 2006-10-11

Zhang San 13612312331 Bachelor degree 2006-10-15

Zhang Si 021-55665566 Graduated from technical secondary school 2006-10-15

(a) There is a new record (Xiao Wang 13254748547 graduated from high school 2007-05-06). Please use SQL statements to add it to the table

INSERT INTO User('Name','Tel','Content','Date') VALUES('Xiao Wang','13254748547','High School Graduation','2007-05-06')

(b) Please use sql statement to update Zhang San’s time to the current system time

UPDATE User SET Date=DATE_FORMAT(NOW(),'%Y-%m-%d') WHERE Name='Zhang San'

(c) Please write to delete all records named Zhang Si

DELETE FROM User WHERE Name='张思'

36. Please write the meaning of data type (int char varchar datetime text); what is the difference between varchar and char (2 points)

char is a fixed-length character, and the insufficient length is filled with spaces; varchar does not seem to have this type,

37. MySQ auto-increment type (usually table ID field) must be set to (?) field (1 point)

38. Write the output result of the following program (1 point)

$b=201;

$c=40;

$a=$b>$c?4:5;

echo $a;

?>

Answer: 4

39. Is there a function that detects whether a variable is set? What is the function that detects whether it is empty? (2 points)

isset();empty();

-------------------------------------------------- ----------------------------------

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

mysql_fetch_array();

41. $arr = array('james', 'tom', 'symfony'); Please print out the value of the first element (1 point)

echo $arr['0'];

42. Please separate the array values ​​in question 41 with ',' signs and merge them into string output (1 point)

$arr_im = implode(",",$arr);

print_r($arr_im);

43. $a = 'abcdef'; Please take out the value of $a and print out the first letter (1 point)

$a = 'abcdef';

echo $a;

$a_exp = substr($a,0,1);

echo "
";

echo $a_exp;

44. Can PHP be connected to databases such as sql server/oracle? (1 point)

Of course

45. Please write the PHP5 permission control modifier (3 points)

PHP5 introduced access modifiers, which are placed in front of property and method declarations to control their visibility. PHP5 supports the following three different access modifications:

1. The default is public, that is, when you do not specify access modifications for properties and methods, it defaults to public. These public items can be accessed inside and outside the class.

  2. Private access modification means that the modified item can only be accessed within the class. If you do not use __get() and __set(), it is best to add private modification to each attribute. You can also add private modifications to methods, such as some functions that are only used in the class. Private-modified items cannot be inherited (more details will be mentioned later in this chapter).

  3. Items modified by protected (protected) can be accessed in the class and its subclasses. Again more details will be mentioned later in this chapter. For now, protected can be regarded as a modification between public and private.

46. Please write the constructor and destructor of php5 (2 points)

If you declare a function in a class, named __construct, this function will be treated as a constructor and executed when creating an object instance. To be clear, __ is two underscores. Like Like any other function, a constructor may have parameters or default values. You can define a class to create an object and put all its properties in a statement.

You can also define a function called __destruct, which PHP will call before the object is destroyed. It is called a destructor.

-------------------------------------------------- ----------------------------------

47. Please use PHPMYADMIN to complete the following -- (not tested)

(1) Create a news release system. The table name is message and has the following fields (3 points)

id article id

title article title

content article content

category_id article category id

hits clicks

(2) The same news release system as above: the comment table records the content of user replies, and the fields are as follows (4 points)

comment_id reply id

id article id, associated with the id in the message table

comment_content reply content

Now you need to query the database to get a list of article titles in the following format, and sort them by the number of replies, with the highest reply at the top

Article id Article title Number of clicks Number of replies

Use a SQL statement to complete the above query. If the article has no replies, the number of replies will be displayed as 0

select message.id,message.title, message.hits sum(select count(0) from comment where message.id=comment.id) as comsums from message comment order by comsums;

(3) In the above content management system, the category table stores classification information, and the fields are as follows (3 points)

category_id int(4) not null auto_increment;

categroy_name varchar(40) not null;

When the user enters an article, select the article category by selecting the drop-down menu

Write how to implement this drop-down menu

//adodb used below

$cnn =& NewADOConnection('mysql');

$cnn -> Connect($db_hostspec, $db_username, $db_password, $db_database);

$cnn -> SetFetchMode(ADODB_FETCH_ASSOC);

if (!$cnn) message("Unable to connect to database $db_database");

$sql = "SELECT * FROM `category` WHERE 1;

$rst =& $cnn -> Execute($sql);

if (!$rst) die($cnn -> ErrorMsg());

$arr_categroy = $rst -> GetArray();


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477524.htmlTechArticleJob hunting and recruitment often require interviews and written tests. As a PHP programmer, you will have more or less similar experiences as follows: These are PHP interview questions that I collected and sorted out. I hope it will be useful to my peers...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn