Home Backend Development PHP Tutorial The most complete and detailed PHP interview questions (with answers)

The most complete and detailed PHP interview questions (with answers)

May 14, 2018 pm 02:24 PM
php interview

This article introduces the most complete and detailed PHP interview questions (with answers), which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

Related Recommended: Summary of PHP interview questions in 2019 (collection)

1. What does __FILE__ mean? (5 points)
The full path and file name of the file. If used in an include file, returns the include file name. As of PHP 4.0.2, __FILE__ always contains an absolute path, while previous versions sometimes contained a relative path.
2. How to obtain the client’s IP address? (5 points)

$_SERVER[‘REMOTE_ADDR’]
Copy after login

3. Write a statement that uses the header function to jump to the page (5 points)

Header(‘location:index.php’);
Copy after login

4. $str is a piece of html text, use Regular expression to remove all js scripts (5 points)

$pattern = ‘/<script.*>\.+<\/script>/’;
Preg_replace($pattern,’’,$str);
Copy after login

5. Write a statement to remove null values ​​​​in an array (5 points)

$arr = array(‘’,1,2,3,’’,19);
Copy after login

First method:

$array1 = array(&#39;  &#39;,1,&#39;&#39;,2,3);
print_r(array_filter($array1, "del"));
function del($var)
{
       return(trim($var)); 
}
Copy after login

Second method:

$arr=array("",1,2,3,"");
$ptn="/\S+/i";
print_r(preg_grep($ptn,$arr));
Copy after login

6. Write a function to obtain the current timestamp and a method to print the time of the previous day (Format: Year-Month-Day Hour:Minute:Second) (5 points)

Time();
Date(“Y-m-d H:i:s”,Strtotime(“-1 day”));
Copy after login

7. Write the function for encoding conversion in PHP (5 points)

Iconv(‘utf-8’,’gb2312’,$str);
Copy after login

8, $str = "1,3,5,7,9,10,20", what function can be used to convert the string str into an array containing each number? (5 points)

$arr = explode(“,”,$str);
Copy after login

9. The role of the serialize() /unserialize() function (5 points)
The explanation of serialize() and unserialize() in the PHP manual is:
serialize — Generates a representation of a storable value. The return value is a string. This string contains a byte stream representing value without losing its type and structure and can be stored anywhere.
unserialize — Create a PHP value from a stored representation
Specific usage:

$arr = array(“测试1″,”测试2″,”测试3″);//数组
$sarr = serialize($arr);//产生一个可存储的值(用于存储)
Copy after login

//Use any method (for example: if you save $sarr in a text file you You can use file_get_contents to get the stored value and save it in $newarr;

$unsarr=unserialize($newarr);//从已存储的表示中创建 PHP 的值
Copy after login

10. Write a function with the parameters as year and month, and the output result is the number of days in the specified month (5 points)

Function day_count($year,$month){
Echo date(“t”,strtotime($year.”-”.$month.”-1”));
}
Copy after login

11. The path of a file is /wwwroot/include/page.class.php. Write a method to obtain the file extension (5 points)

$arr = pathinfo(“/wwwroot/include/page.class.php”);
$str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));
Copy after login

12. Which PHP template engine have you used? (5 points)
Smarty, the template engine that comes with thinkphp
13. Please simply write a class, instantiate this class, and write statements to call the properties and methods of the class (5 points)

Class myclass{
Public $aaa;
Public $bbb;
Public function myfun(){
Echo “this is my function”;
}
}
$myclass = new myclass();
$myclass->$aaa;
$myclass->myfun();
Copy after login

14. The table friend has been built in the local mysql database db_test. The database connection user is root and the password is 123
The friend table fields are: id, name, age, gender, phone, email
Please use php to connect to mysql, select all records with age > 20 in the friend table, print the results, and count the total number of query results. (5 points)

<?php
$link = Mysql_connect(“localhost”,”root”,”123”) or die(“数据库连接失败!”);
Mysql_select_db(“db_test”,$link) or die(“选择数据库失败!”);
$sql = “select id,name,age,gender,phone,email from friend where age>20”;
$result = mysql_query($sql);
$count = mysql_num_rows($result);
While($row = mysql_fetch_assoc($result)){
Echo $row[‘id’];
….
}
Copy after login

15. There are two tables below
user table field id (int), name (varchar)
score table field uid (int), subject (varchar) ), score (int)
The uid field of the score table is associated with the id field of the user table
Required to write the following sql statement
1) Insert a new record in the user table and insert it in the score table Two records associated with the newly added record (5 points)
2) Obtain the five records with the highest score for the user whose uid is 2 in the score table (5 points)
3) Use a joint query to obtain the name " The total score of the user named "李思" (5 points)
4) Delete the user named "李思", including the score record (5 points)
5) Clear the score table (5 points)
6 ) Delete the user table (5 points)

1). mysql_query(“insert into user(name) values(‘test’)”);
$id = mysql_insert_id();
Mysql_query(“insert into score(uid,subjext,score) values(“.$id.”,’english’,’99’)”);
2).$sql = select uid,sunjext,score from score where uid=2 order by score desc limit 0,5;
3).select s.score from score s RIGHT JOIN user u ON u.id=s.uid where u.name=’张三;
4).delete from score where uid in(select id from user where name=’李四’);
Delete from user where name=’李四’;
5).delete from score;
6).drop table user;
Copy after login

Related recommendations:

php interview question 8: The difference between innoDB and myisam

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

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1668
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 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

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 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.

See all articles