Home Backend Development PHP Tutorial Good PHP interview questions and answers

Good PHP interview questions and answers

Jul 25, 2016 am 08:53 AM

  1. strrev($str)
  2. {
  3. $len=strlen($str);
  4. $newstr = '';
  5. for($i=$len;$i>=0;$i--)
  6. {
  7. $newstr .= $str{$i};
  8. }
  9. return $newstr;
  10. }
Copy code

15. Implement a method to intercept Chinese strings without garbled characters.

Answer: mb_substr()

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

  1. Name user
  2. name tel content date
  3. Zhang San 13333663366 College graduate 2006-10-11
  4. Zhang San 13612312331 Undergraduate graduate 2006-10-15
  5. Zhang Si 021-55665566 Technical secondary school graduate 2006 -10-15
  6. Answer: select name,tel,content,date from user where name='张三'
Copy code

17. How to use the following class and explain what it means?

  1. class test
  2. {
  3. get_test($num)
  4. {
  5. $num=md5(md5($num)."en");
  6. return $num;
  7. }
  8. }
Copy code

Answer: Usage: $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 out .jpg or jpg,

Answer: Use more than five methods to get the extension of a file

  1. 1)

  2. get_ext1($file_name)
  3. {
  4. return strrchr($file_name, '.');
  5. }
  6. 2)
  7. get_ext2($file_name)
  8. {
  9. return substr( $file_name, strrpos($file_name, '.'));
  10. }
  11. 3)
  12. get_ext3($file_name)
  13. {
  14. return array_pop(explode('.', $file_name));
  15. }

  16. 4)

  17. get_ext4($file_name)
  18. {
  19. $p = pathinfo($file_name);
  20. return $p['extension'];
  21. }
  22. 5)
  23. get_ext5($file_name)
  24. {
  25. return strrev (substr(strrev($file_name), 0, strpos(strrev($file_name), '.')));
  26. }

Copy code

19. How to modify the session survival time

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. lifetime, this function must be called before the session_start() function is called:

  1. <?php
  2. //Save for one day
  3. $lifetime = 24 * 3600;
  4. session_set_cookie_params($lifetime);
  5. session_start();
  6. $_session["admin"] = true;
  7. ?>
Copy code

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". 30. Please give an example of what methods you use to speed up page loading during your development process. a. Generate static html b. Generate xml c. If you don't use a database, try not to use a database to store variable parameters in text. d. Accelerate with zend answer:

  1. function test($str){
  2. $arr1=explode('_',$str);
  3. //$arr2=array_walk($arr1,ucwords( ) );

  4. $str = implode(' ',$arr1);

  5. return ucwords($str);
  6. }
  7. $aa='open_door';
  8. echo test($aa);
  9. ?>

Copy code

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

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

Answer: (strtotime(‘2007-3-6’)-strtotime(‘2007-2-5’))/3600*24

23. There are three columns a, b, and c in the table, which can be implemented using SQL statements: 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.

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?

Answer: (1) Choose the most efficient order of table names

(2) Connection order in where clause

(3) Avoid using ‘*’ in the select clause

(4) Replace having clause with where clause

(5) Improve sql efficiency through internal functions

(6) Avoid using calculations on indexed columns.

(7) Improve the efficiency of group by statement by filtering out unnecessary records before group by.

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

mysql_fetch_row() stores a database column in a zero-based array, with the first column at index 0 of the array, 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);

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 No. $regexpression .= "([0-9]+)/";// again corresponds to one or more 0-9$regexpression .= "([0-9]+)"; as for \2/\1/ \3 is used to correspond to brackets. The first bracket corresponds to the month,

27.What is the gd library used for?

Answer: This function 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. Answer: Only open the server resources when they are needed, close the 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 value, passing reference and passing address in php? 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 what it passes is an address, not an ordinary int. Then 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 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

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

The above shares some PHP interview questions and related answers, I hope it will be helpful to everyone.



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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
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.

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

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

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

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.

See all articles