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)
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);
echo $num;?>
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"
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!

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

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.

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.

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.

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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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
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
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use