search
HomeBackend DevelopmentPHP TutorialPHP2017 latest version interview questions (with answers)

Seeing that many friends are asking for PHP interview questions, I collected some interview questions for you. These are all the latest questions in 2017. I hope they will help you improve your skills. I also wish you can get into the company you want to work in.

This article collects and analyzes the latest 2017 PHP interview questions in more detail. Share it with everyone for your reference. The details are as follows:


1. Use PHP to print out the time of the previous day in the format of 2006-5-10 22:21:21 (2 minutes)

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

print_r($a);

2, echo The difference between (), print() and print_r() (3 points)

echo and print are not a function, but a language structure

int print(string $arg), only one parameter

echo arg1,arg2; can output multiple parameters and return void

echo and print can only print out string, not the structure

print_r can print out 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 achieve string flipping?(3 points)

English :

strrev($a)

Chinese or other text:

Chinese: GB2312, the code is encoded using GB2312

function reverse($str)

{

$ret = "";

len=mbstrwidth(str,"GB2312");

for(i=0;i

{

arr[]=mbsubstr(str, $i, 1, "GB2312");

}

return implode("", array_reverse($arr));

}

print_r(reverse("Hello"));

6. Methods to optimize MYSQL database. (4 points, write more and get more)

Statement aspects:

1 Use index to increase query efficiency

2 Optimize query statements and improve index hit rate

Aspects involved in the database:

1 Construct sub-databases and tables to improve the storage and expansion capabilities of the database

2 Use different storage engines as needed


7. The meaning of PHP (send 1 point)

Hypertext Preprocessing Language

Hypertext PreProcessor


8 , What is the function for MYSQL to obtain the current time?, and the function for formatting the date is (2 points)

CURRENT_TIMESTAMP()

DATE_FORMAT()

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

9. Method to intercept Chinese text strings without garbled characters. (3 points)

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

10. Have you ever used version control software? If so, have you used it? What is the name of the version control software? (1 point)

svn

git


11. Have you ever used a template engine? If there is a template engine you use, what is the name? (1 point)

smarty


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

XXX


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

1 Effectively use cache to increase cache hit rate

2 Use load balancing

3 Use CDN to store and accelerate static files

4 Ideas to reduce database Use

5 Check where the bottleneck of statistics is


14. Use PHP to write the code to display the client IP and server IP 1 point)

$_SERVER["REMOTE_ADDR"]

$_SERVER["SERVER_ADDR"]


15. What is the difference between the statement include and require ?To avoid including the same file multiple times, you can use (?) statements to replace them? (2 points)

When it fails:

include generates a warning, while require generates a direct error interrupt

require is loaded before running

include is loaded at runtime

require_once

include_once


16. How to modify the survival time of SESSION (1 minute).

session_set_cookie_params


17. There is a web page address, such as the homepage of the PHP Research Laboratory : http://www.jb51.net/index.html, how to get its content? ($1 point)

file_get_contents

curl


18. 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 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 =

good test

EOD;

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

asp needs to rely on IIS and is a language developed by Microsoft

php and jsp can rely on other servers such as apache or nginx


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

model: data structure layer

view: display

control: Receive and judge the input


#22. Write the SQL of the names of the ten people with the most posts. Use the following table: members(id,username,posts,pass,email )(2 minutes)

select top 10 id,username from members order by posts desc


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

& means passing by reference

Passing the parameter by reference in the function will change the parameter

Generally in the output parameter When there are more than one, you can consider using references


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

Set the display level of error


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

$argc --Get the number of parameters

$argv --Get the parameter list


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

session_set_cookie_params


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

alert()

confirm()

promote()

focus()


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

window.location.href="#"

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

@represents all warnings and is 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 the attributes of a class? (2 points)

class A

{

public $name = "A";

}

$a = new A();

n=a-> ;name;

print_r($n);

34, what is between mysql_fetch_row() and mysql_fetch_array Difference? (1 point)

mysql_fetch_array() is an extended version of mysql_fetch_row(). In addition to storing data in an array as a numerical index, you can also store data as an associative index, using the field name as the key.

mysql_connect("localhost", "mysql_user", "mysql_password") or

die("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 for? ( 1 point)

Dynamic open image processing library


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

echo "{html}"

echo {html}

EOD;

37. 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()


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 be entered? (1 point) 10

$num = 10;

function multiply(){

num=num * 10;

}

multiply();

echo $num;

?>


40. Use php to write a simple query to find all the people named "Zhang San" Content and print it out (2 points)

Table name UserName Tel Content Date

Zhang San 13333663366 College graduate 2006-10-11

Zhang San 13612312331 Undergraduate graduate 2006-10 -15

Zhang Si 021-55665566 Technical secondary school graduate 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);

$sql = sprintf("select * from %s where UserName = '%s' ",

"Table name",

"Zhang San");

values=mysqlquery(sql);

while(item=mysqlfetchqueryarray( values))

{

echo sprintf("Username: %s, phone number %s, education: %s, graduation date: %s",

item[ 'UserName'],item['Tel'], item['Content'],item['Date']

);

}

41. 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;

}

}

$test = new test();

ret=test->Get_test(11);

print_r($ret);exit;

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


42. Write the format of the SQL statement: insert, update, delete (4 points)

Table name UserName Tel Content Date

Zhang San13333663366 College graduate 2006-10-11

Zhang San 13612312331 Graduated from undergraduate 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 High school graduate 2007-05-06) Please use SQL statement to add to the table

insert into table name values('Xiao Wang', '13254748547', 'High school graduate', '2007-05-06 ')

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

update table name set Date = GETDATE() where UserName = "Zhang San"

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

delete from indicates where UserName = "Zhang Si"


##43, Please write down the meaning of the data type (int char varchar datetime text); What is the difference between varchar and char (2 points)

int integer type

char fixed length storage

varchar stores variable length

datetime time

text stores variable length

varchar is variable length

char(20) fixed length


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

auto_increment


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

$b=201;

$c=40;

a=b>$c?4:5;

echo $a;


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

isset()

empty()

47. What is the function that obtains the total number of query result sets? (1 point)

mysql_num_rows()


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


print_r($arr[0]);

reset($arr);

print_r(current($arr));

print_r(array_shift($arr));

49. Please use the value of the array in question 41 Separate with ',' signs and merge into string output (1 point)

implode


##50. a='abcdef'; Please take out the value of a And print out the first letter (1 point)

$a[0];

substr($a, 0, 1);

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

Yes

There are ready-made libraries


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

public

private

protected


53. Please write the constructor and destructor of php5 (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

For example: http://www.sina.com.cn/abc/de/fg.php?id=1 You need to remove php or .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 paths of two files

For example, $a = '/a/b/c/d/e. php';

$b = '/a/b/12/34/c.php';

The calculated relative path of b relative to a should be http://www. jb51.net/12/34/c.php will add

$a = '/a/b/c/d/e. php';

$b = '/a/b/12/34/c.php';

//Get the relative path of path relative to conpath

function sGetRelativePath(path,conpath)

{

pathArr=explode("/",path);

conpathArr=explode("/",conpath);

$dismatchlen = 0;

for(i=0;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,a));


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

function aGetAllFile($folder)

{

$aFileArr = array();

if(is_dir($folder))

{

handle=opendir(folder);

while((file=readdir(handle)) != = false)

{

//If it is. 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));

The above are the latest interview questions and answers I collected, which will be helpful to everyone.

Related reading:

Common PHP interview questions and answering techniques in 2017

8 PHP interview questions reflect your understanding of PHP Level

Summary of written test questions in php interview questions

The above is the detailed content of PHP2017 latest version interview questions (with answers). For more information, please follow other related articles on the PHP Chinese website!

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
PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP: The Foundation of Many WebsitesPHP: The Foundation of Many WebsitesApr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

Beyond the Hype: Assessing PHP's Role TodayBeyond the Hype: Assessing PHP's Role TodayApr 12, 2025 am 12:17 AM

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

What are Weak References in PHP and when are they useful?What are Weak References in PHP and when are they useful?Apr 12, 2025 am 12:13 AM

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

Explain the __invoke magic method in PHP.Explain the __invoke magic method in PHP.Apr 12, 2025 am 12:07 AM

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use