Table of Contents
33 PHP common interview questions and answers, 33 PHP test questions and answers
Home Backend Development PHP Tutorial 33 common PHP interview questions and answers, 33 PHP test questions and answers_PHP tutorial

33 common PHP interview questions and answers, 33 PHP test questions and answers_PHP tutorial

Jul 13, 2016 am 09:47 AM
php interview questions Interview questions

33 PHP common interview questions and answers, 33 PHP test questions and answers

1. In PHP, the name of the current script (excluding path and query string) record In the predefined variable (1); and the URL linking to the current page is recorded in the predefined variable (2).

Copy code The code is as follows:
Answer: echo $_SERVER['PHP_SELF']; echo $_SERVER["HTTP_REFERER"];

2. The execution program segment will output (3).

Copy code The code is as follows:
Answer: 0

3. In HTTP 1.0, the meaning of status code 401 is (4); if a "File not found" prompt is returned, the header function can be used, and its statement is (5).

Copy code The code is as follows:
Answer: (4) Unauthorized (5) header("HTTP/1.0 404 Not Found");

4. The function of array function arsort is (6); the function of statement error_reporting(2047) is (7).

Copy code The code is as follows:
Answer: (6) Reverse sort the array and maintain the index relationship (7) All errors and warnings

5. Write a regular expression to filter all JS/VBS scripts on the web page (that is, remove the tags and their contents): (9).

Copy code The code is as follows:
Answer: /<[^>].*?>.*?/si

6. Install PHP as an Apache module. In the file http.conf, first use statement (10) to dynamically load the PHP module,

Then use statement (11) to cause Apache to process all files with the extension php as PHP scripts.

Copy code The code is as follows:
Answer: (10) LoadModule php5_module "D:/xampp/apache/bin/php5apache2.dll"
(11) AddType application/x-httpd-php-source .phps
          AddType application/x-httpd-php .php .php5 .php4 .php3 .phtml

7. The statements include and require can include another file into the current file. The difference between them is (12); in order to avoid including the same file multiple times, you can use the statement (13) to replace them.

Copy code The code is as follows:
Answer: (12) When an exception occurs, include generates a warning and require generates a fatal error (13) require_once()/include_once()

8. The attributes of the class can be serialized and saved to the session, so that the entire class can be restored later. The function to be used is (14).

Copy code The code is as follows:
Answer: serialize() /unserialize()

9. The parameter of a function cannot be a reference to a variable, unless (15) is set to on in php.ini.

Copy code The code is as follows:
Answer: allow_call_time_pass_reference

10.The meaning of LEFT JOIN in SQL is (16).

If tbl_user records the student’s name (name) and student number (ID),

tbl_score records the student number (ID), test score (score), and test subject (subject) of the students (some students were expelled after taking the exam and there is no record of them),

If you want to print out the name of each student and the corresponding total score of each subject, you can use SQL statement (17).

Copy code The code is as follows:
Answer: (16) Natural left outer join
(17) select name, count(score) as sum_score from tbl_user left join tbl_score on tbl_user.ID=tbl_score.ID group by tbl_user.ID

11.. In PHP, heredoc is a special string, and its end flag must be (18).

Copy code The code is as follows:
Answer: The line where the end identifier is located cannot contain any other characters except ";"

12. Use PHP to print out the time of the previous day in the format of 2006-5-10 22:21:21

Copy code The code is as follows:
Answer: echo date('Y-m-d H:i:s', strtotime('-1 day'));

13.The difference between echo(), print() and print_r()

Copy code The code is as follows:
Answer: echo is a language structure with no return value; the print function is basically the same as echo, except that print is a function with a return value; print_r is recursive printing, used to output array objects

14. How to implement string flipping?

Copy code The code is as follows:
Answer: Just use the strrev function. Don’t use PHP’s built-in one, just write it yourself:
strrev($str)
{
$len=strlen($str);
$newstr = '';
for($i=$len;$i>=0;$i--)
{
          $newstr .= $str{$i};
}
Return $newstr;
}

15. A method to intercept Chinese text strings without garbled characters.

Copy code The code is as follows:
Answer: mb_substr()

16. Use php to write a simple query to find all the content named "Zhang San" and print it out

Table name User

Name Tel       Content Date

Zhang San 13333663366 College graduate 2006-10-11

Zhang San 13612312331 Undergraduate degree 2006-10-15

Zhang Si 021-55665566 Technical secondary school graduate 2006-10-15

Copy code The code is as follows:
Answer: SELECT Name,Tel,Content,Date FROM User WHERE Name='张三'

17. How to use the following classes and explain what they mean?

class test
{
Get_test($num)
{
          $num=md5(md5($num)."En");
         return $num;
}
}

Answer: Usage:

Copy code The code is as follows:
$get_test = new test();
$result = $get_test->Get_test(2);

The $num variable is md5ed twice and returned. The parameters in the second md5 are added with En

after the first md5($num)

18. Use more than five ways to get the extension of a file

Required: dir/upload.image.jpg, find .jpg or jpg,

Copy code The code is as follows:
Answer: Use more than five methods to get the extension of a file
1)
get_ext1($file_name)
{
Return strrchr($file_name, '.');
}
2)
get_ext2($file_name)
{
Return substr($file_name, strrpos($file_name, '.'));
}
3)
get_ext3($file_name)
{
Return array_pop(explode('.', $file_name));
}
4)
get_ext4($file_name)
{
$p = pathinfo($file_name);
Return $p['extension'];
}
5)
get_ext5($file_name)
{
Return strrev(substr(strrev($file_name), 0, strpos(strrev($file_name), '.')));
}

19. How to modify the survival time of SESSION

This library allows you to process and display graphics files in various formats. Another common use of it is to create graphics files. Another option besides GD is ImageMagick, but this function library is not built into PHP and must be installed on the server by the system administrator. Answer: In fact, Session also provides a function session_set_cookie_params(); to set the Session's For lifetime, this function must be called before the session_start() function is called:

<?php
// Save for one day
$lifeTime = 24 * 3600;
session_set_cookie_params($lifeTime);
session_start();
$_SESSION["admin"] = true;
?>

20. Please write a function to achieve the following functions: The string "open_door" is converted into "OpenDoor", "make_by_id" is converted into "MakeById".

Copy code The code is as follows:
Answer:
Function test($str){
$arr1=explode('_',$str);
//$arr2=array_walk($arr1,ucwords( ));
$str = implode(' ',$arr1);
return ucwords($str);
}
$aa='open_door';
echo test($aa);
?>

21. How to use PHP environment variables to get the content of a web page address? How to get the ip address?

Copy code The code is as follows:
Answer: $_SERVSR[‘REQUEST_URI’]
$_SERVER[‘REMOTE_ADDR’]

22. Find the difference between two dates, such as the date difference between 2007-2-5 ~ 2007-3-6

Copy code The code is as follows:
Answer: (strtotime(‘2007-3-6’)-strtotime(‘2007-2-5’))/3600*24

23. There are three columns A, B, and C in the table. Use SQL statements to implement this: when column A is greater than column B, select column A, otherwise select column B. When column B is greater than column C, select column B, otherwise select column C.

Copy code The code is as follows:
Answer: select case when A>B then A else B end,
case when B>C then B else C end
From test

24. Please briefly describe the method to optimize the execution efficiency of SQL statements in the project. From what aspects, how to analyze the performance of SQL statements?

Copy code The code is as follows:
Answer: (1) Choose the most efficient table name order
(2) Connection order in the WHERE clause
(3) Avoid using ‘*’
in the SELECT clause (4) Replace the HAVING clause with the Where clause
(5) Improve SQL efficiency through internal functions
(6) Avoid using calculations on index columns.
(7) Improve the efficiency of the GROUP BY statement by filtering out unnecessary records before GROUP BY.

25.What is the difference between mysql_fetch_row() and mysql_fetch_array()?

Copy code The code is as follows:
mysql_fetch_row() stores a database column in a zero-based array, with the first column at array index 0, the second column at index 1, and so on. mysql_fetch_assoc() stores a column of the database in an associative array. The index of the array is the field name. For example, my database query returns the three fields "first_name", "last_name", and "email". The index of the array is "first_name", "last_name" and "email". mysql_fetch_array() can return the values ​​of both mysql_fetch_row() and mysql_fetch_assoc().

26.What is the following code used for? Please explain.

$date='08/26/2003';print ereg_replace("([0-9] )/([0-9] )/([0-9] )","\2/\1/ \3",$date);

Copy code The code is as follows:
This is to convert a date from MM/DD/YYYY format to DD/MM/YYYY format. A good friend of mine told me that this regular expression can be disassembled into the following statements. For such a simple expression, there is no need to disassemble it. It is purely for the convenience of explanation:
// Corresponds to one or more 0-9, followed by a slash $regExpression = "([0-9] )/";// Corresponds to one or more 0-9, followed by another slash $ regExpression .= "([0-9] )/";// Again corresponds to one or more 0-9$regExpression .= "([0-9] )"; as for \2/\1/\3 Used to correspond to brackets. The first bracket corresponds to the month,

27.What is the GD library used for?

Copy code The code is as follows:
Answer: This library allows you to process and display graphics files in various formats. Another common use of it is to create graphics files. Another option besides GD is ImageMagick, but this library is not built into PHP and must be installed on the server by the system administrator

28. Please give an example of what methods you use to speed up page loading during your development process

Copy code The code is as follows:
Answer: Open only when server resources are needed, close server resources in time, add indexes to the database, and the page can generate static, pictures and other large files on a separate server. Use code optimization tools

29. To prevent SQL injection vulnerabilities, the __addslashes___ function is generally used.

30.What is the difference between passing values, passing references, and passing addresses in PHP?

Copy code The code is as follows:
Answer: Passing by value is to assign the value of the actual parameter to the row parameter. Then the modification of the row parameter will not affect the value of the actual parameter
Passing address is a special way of passing value, but it passes an address, not an ordinary int. After passing the address, the actual parameters and line parameters point to the same object

31. How to determine whether a window has been blocked through javascript

Copy code The code is as follows:
Answer: Get the return value of open(). If it is null, it is blocked

33. For websites with large traffic, what methods do you use to solve the traffic problem

Copy code The code is as follows:
Answer: First, confirm whether the server hardware is sufficient to support the current traffic
Second, 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

The above is the entire content of this article. I hope it will be helpful to everyone learning php.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1027501.htmlTechArticle33 PHP common interview questions and answers, 33 PHP test questions and answers 1. In PHP, the current script The name (excluding path and query string) is recorded in the predefined variable (1); while the link to...
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 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)

Five common Go language interview questions and answers Five common Go language interview questions and answers Jun 01, 2023 pm 08:10 PM

As a programming language that has become very popular in recent years, Go language has become a hot spot for interviews in many companies and enterprises. For beginners of the Go language, how to answer relevant questions during the interview process is a question worth exploring. Here are five common Go language interview questions and answers for beginners’ reference. Please introduce how the garbage collection mechanism of Go language works? The garbage collection mechanism of the Go language is based on the mark-sweep algorithm and the three-color marking algorithm. When the memory space in the Go program is not enough, the Go garbage collector

Summary of front-end React interview questions in 2023 (Collection) Summary of front-end React interview questions in 2023 (Collection) Aug 04, 2020 pm 05:33 PM

As a well-known programming learning website, php Chinese website has compiled some React interview questions for you to help front-end developers prepare and clear React interview obstacles.

Summary of PHP interview questions in 2023 (Collection) Summary of PHP interview questions in 2023 (Collection) Feb 26, 2019 am 10:49 AM

If you are looking for a job in PHP development, mastering the latest PHP interview question skills in advance will definitely help you get twice the result with half the effort in the job search process. As a well-known PHP learning platform in the industry, PHP Chinese website naturally has the most popular and comprehensive PHP interview questions, including basic PHP interview questions, advanced PHP interview questions and common PHP interview questions!

A complete collection of selected Web front-end interview questions and answers in 2023 (Collection) A complete collection of selected Web front-end interview questions and answers in 2023 (Collection) Apr 08, 2021 am 10:11 AM

This article summarizes some selected Web front-end interview questions worth collecting (with answers). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Summary of the latest PHP interview questions in 2023 (with answers) Summary of the latest PHP interview questions in 2023 (with answers) Feb 23, 2019 am 10:53 AM

1. Please introduce yourself? Answer: My name is xxx, from Beijing. I graduated from the Computer Department of xx University in 20xx. After graduation, I worked in PHP development in Wuhan for x years. The company is an outsourcing company, mainly engaged in WeChat development. Public account promotion, mall, and forum development 2. What projects are you responsible for in the company?

50 Angular interview questions you must master (Collection) 50 Angular interview questions you must master (Collection) Jul 23, 2021 am 10:12 AM

This article will share with you 50 Angular interview questions that you must master. It will analyze these 50 interview questions from three parts: beginner, intermediate and advanced, and help you understand them thoroughly!

Interviewer: How much do you know about high concurrency? Me: emmm... Interviewer: How much do you know about high concurrency? Me: emmm... Jul 26, 2023 pm 04:07 PM

High concurrency is an experience that almost every programmer wants to have. The reason is simple: as traffic increases, various technical problems will be encountered, such as interface response timeout, increased CPU load, frequent GC, deadlock, large data storage, etc. These problems can promote our Continuous improvement in technical depth.

Take a look at these front-end interview questions to help you master high-frequency knowledge points (4) Take a look at these front-end interview questions to help you master high-frequency knowledge points (4) Feb 20, 2023 pm 07:19 PM

10 questions every day. After 100 days, you will have mastered all the high-frequency knowledge points of front-end interviews. Come on! ! ! , while reading the article, I hope you don’t look at the answer directly, but first think about whether you know it, and if so, what is your answer? Think about it and then compare it with the answer. Would it be better? Of course, if you have a better answer than mine, please leave a message in the comment area and discuss the beauty of technology together.

See all articles