Home >Backend Development >PHP Tutorial >Analysis of several interview questions about PHP

Analysis of several interview questions about PHP

巴扎黑
巴扎黑Original
2017-08-09 14:24:101281browse

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

## $yesterday = mktime(0, 0 , 0, date("m") , date("d")-1 , date("Y"));

echo date("Y-M-d h:i:s" , $yesterday);

Note: mktime returns unix timestamp.

int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]]

 2. The difference between echo(), print(), print_r()

You can understand it by looking at the function definition on php.net:

#printOutput a string

##              

echoOutput one or more strings
#          

var_dump

Dumps information about a variable##            

print_r Prints human-readable information about a variable In addition:

                                                                              printf

—  

Output a formatted string                                                                          

sprintf

—   Return a formatted string

           

flush —   Flush the output buffer 3, the template that can separate HTML and PHP

# ste MARTY (very good template engine), PHPLIB , Fasttemplete,

php4 comes with (IntegratedTemplate, IntegratedTemplateExtension)

Another:

# 1. You can implement one yourself. Commonly used HTML tags such as select, input, etc. are convenient for program and database processing. Then use the program to call the static page containing the template tag. However, smarty is based on the caching mechanism. There is a templates_c directory to generate temporary files for storage. This aspect is relatively advanced. If you write it yourself, it will be more complicated.

2.Separating logic and performance is the right way, rather than simply separating HTML and PHP

3. Pay attention to the difference between template engines and frameworks, and consider it from the perspective of MVC.

## 4. What tools are used for version control?

# #      

svn,cvs, VSS(ms)## 5. How to achieve string flipping?

Strrev ()

## This If you consider sufficient (Chinese character problem), I find the following code:

#

1.function reverse($str)
{
     $len=strlen($str);
     $newstr = '';
     for($i=$len;$i>=0;$i--)
     {
         $newstr .= $str{$i};
     }
     return $newstr;
}

    2. join("",array_reverse(str_split($str,1))),str_split($str,1)函数按长度分割字符串。explode()按分割符分割字符串.

    3.function rev_str($str)
   {
    $len = strlen($str);
    for($i=0;$i<$len;$i++)
    {
      $temp_str=substr($str,0,1);
      if(ord($temp_str) > 127)
      {
         $i++;
         if($i<$len)
         {
           $new_str[]=substr($str,0,3);
           $str=substr($str,3);
          }
       }
   else
      {
        $new_str[]=substr($str,0,1);
        $str=substr($str,1);
      }
    }
    return join(array_reverse($new_str));
}

6. Methods to optimize MYSQL database.

Mainly from several perspectives: Optimizing hardware, optimizing disk, optimizing operating system, selecting application programming interface, etc.

                                                                                                                                                                                                         Reference: http://www.phpdo.net/index.php/optimization-mysql.html

Use index etc.  

7. What does PHP mean?


#  8、MYSQL取得当前时间的函数是?格式化日期的函数是

   mysql:    now() ;      date_format();

              php:      time();   date();

  9、实现中文字串截取无乱码的方法。

          其核心是处理中文问题,见blog:http://www.cnblogs.com/nbkhic/archive/2011/07/16/2108335.html

         很多处理都是这些思路,如何判断汉字边界的问题,防止出现汉字截断。


  10、用PHP写出显示客户端IP与服务器IP的代码
              $_SERVER["SERVER_ADDR"]         这个是服务器ip
              $_SERVER["REMOTE_ADDR"]        这个是客户端ip
              _SERVER显示服务器和执行环境信息。http://php.net/manual/en/reserved.variables.server.php
                     11、语句include和require的区别是什么?为避免多次包含同一文件,可用(?)语句代替它们? 

                    include如果包含出错,报错继续执行。

                    requre如果出错,终止执行脚本。

                    requre_once() ; 包含一次

更深入一步理解:http://blog.csdn.net/followingturing/article/details/8102789        

  12、如何修改SESSION的生存时间

                    通常是修改php.ini中某个配置项值,可google之。               

  13、有一个网页地址, 比如PHP研究室主页: http://www.phpv.net/index.html,如何得到它的内容?

                     file_get_contents();

                     fopen()都可以。  

                     复杂的话,用curl。

  14、在HTTP 1.0中,状态码401的含义是?;  如果返回“找不到文件”的提示,则可用 header 函数,其语句为?;

                       401:需要用户验证。 get_headers();

                       其它常用:200,301,302,404等等。 详见:http://baike.baidu.com/view/1790469.htm                       

  15、在PHP中,heredoc是一种特殊的字符串,它的结束标志必须?

                    非常好的一项技术,用好了很方便,本质一句话:字符串输出技术

http://blog.csdn.net/followingturing/article/details/8102862

#16. Talk about the advantages and disadvantages of ASP, PHP, JSP                                                                                          Me you in illiteracy and ignore it.

17. Talk about the understanding of the MVC ## Series, ignore it.

18. Write the SQL of the names of the ten people with the most posts, using the following table: members(id,username,posts,pass,email)

                           

select top 10 username from members order by posts desc.



 19. Please explain the difference between passing by value and passing by reference in PHP. When to pass value and when to pass reference? past. This If you want to change the variable value, you can pass the address to see the needs.

 20. What is the function of error_reporting in PHP?

            php.net says: “Sets which PHP errors are reported

”              25. Please write a function to verify whether the format of the email is correct (2 points)

 26. Briefly describe how to get the current execution script path, including the obtained parameters. (2 points)

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

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

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

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

31. How to declare a class named "myclass" without methods and The class of the attribute? (1 point)

32. How to instantiate an object named "myclass"? (1 point)

33. How do you access and set the attributes of a class? (2 points)

34. What is the difference between mysql_fetch_row() and mysql_fetch_array? (1 point)

35. What is the GD library used for? (1 point)

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

37. Which of the following functions can open a file to read and write the file? (1 point)
 (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 Points)
 (a) $users[] = 'john';
 (b) array_add($users,'john');
 (c) array_push($users,'john');
 (d) $users ||= 'john';

39. Will the following program be input? (1 point)
 $num = 10;
 function multiply(){
$num = $num * 10;
 }
 multiply();
 echo $num;
 ?>

## 40. Use PHP to write a simple query to find out all the content named "Zhang San" and print it out (2 points)
Table Name UserName Tel Content Date
Zhang San13333663366 College graduate 2006-10-11 Code:
 $mysql_db=mysql_connect("local","root","pass");
 @mysql_select_db("DB",$mysql_db);
 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;
 }
 }
42. Write the format of the SQL statement: insert, update, delete (4 points)
Table name UserName Tel Content Date

in the table (b) Please use sql statement to update Zhang San’s time to the current system time
(c) Please write to delete all the names named Zhang Si Record

43. Please write the meaning of data type (int char varchar datetime text); What is the difference between varchar and char (2 points)
44. MySQ auto-increment type (usually table ID field) must be set to (?) field (1 point)
45. Write the output results of the following program (1 point)
 $b=201;

 $c=40;

 $a=$b>$c? 4:5;
echo $a;
 ?>

 46. Check whether a variable is set Is the function? The function that is empty? (2 points)
47. What is the function that obtains the total number of query result sets? (1 point)
48. $arr = array('james', 'tom', 'symfony'); Please print out the value of the first element (1 point)

49. Please separate the values ​​of the array in question 41 with ',' and merge them into string output (1 point)

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

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

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

53. Please write the constructor and destructor of php5 (2 points)

54. Please use PHPMYADMIN to complete the following

(1) Create a news release system. The table name is message and has the following fields (3 points)
 id article id
 title article title
 content article content
 category_id article category id
Hits Number of clicks

(2) The same news release system as above: The comment table records the content of user replies, and the fields are as follows (4 points)
Comment_id reply id
id article id, associated with the id in the message table
comment_content reply content
Now need to be obtained by querying the database A list of article titles in the following format, sorted by the number of replies, with the highest reply at the top
Article id Number of clicks on the article title Number of replies
Use a SQL statement Complete the above query. If there is no reply to the article, the number of replies will be displayed as 0

(3) In the above content management system, the table category saves classification information, and the fields are as follows (3 points)
Category_id int(4) not null auto_increment;
category_name varchar(40) not null;
When the user enters an article, select it from the drop-down menu Define the article category
Write how to implement this drop-down menu

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

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

 57. The function of array function arsort is ____; the function of statement error_reporting(2047) is ____.

58.The database connection string format in PEAR is ____.

59. Write a regular expression to filter all JS/VBS scripts on the web page (that is, remove the scrīpt tag and its content): ____.

60. To install PHP as an Apache module, in the file http.conf, first use the statement ____ to dynamically load the PHP module, and then use the statement ____ to make Apache All files with the php extension are processed as PHP scripts.

61. Both the include and require statements can include another file into the current file. The difference between them is ____; in order to avoid including the same file multiple times, you can use the statement ___ _to replace them.

62. The attributes of a class can be serialized and saved to the session, so that the entire class can be restored later. The function used for this is ____.

63. The parameter of a function cannot be a reference to a variable, unless ____ is set to on in php.ini.

 64.The meaning of LEFT JOIN in SQL is____. If tbl_user records the student's name (name) and student number (ID), tbl_score records the student's (some students were expelled after the exam and there is no record of them) student number (ID) and test scores (score) as well as test subjects (subject), if you want to print out the name of each student and the corresponding total score of each subject, you can use the SQL statement____.

65. In PHP, heredoc is a special string, and its end mark must be ____.
 
 66. 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 Need to remove php or .php

 67. In HTML language, the page header The internal meta tag can be used to output the encoding format of the file. The following is a standard meta statement
Please use PHP language to write a function to convert the charset in a similar meta tag in a standard HTML page Part of the value is changed to big5
Please note:
1. The complete html page needs to be processed, that is, not just this meta statement
2 . Ignore case
 3. ' and " are interchangeable here
 4. The quotation marks on both sides of 'Content-Type' can be ignored , but 'text/html; charset=gbk' does not work on both sides
 5. Pay attention to handling extra spaces

 68. Write a function to calculate two The relative path of a file
For example $a = '/a/b/c/d/e.php';
$b = '/a/b /12/34/c.php';
Calculate that the relative path of $b relative to $a should be ../../c/d and add () to

69. Write a function that can traverse a All files and subfolders under the folder.

70. Briefly describe the implementation principle of infinite classification in the forum.

71. Use PHP to describe bubble sorting and quick sorting algorithms. The object can be an array

​ ​​

72. Use PHP to describe sequential search and binary search (also called half search) algorithms. Sequential search must consider efficiency, and the object can be an ordered array

73. Write a two-dimensional array sorting algorithm function that can be universal and can call the PHP built-in function










The above is the detailed content of Analysis of several interview questions about PHP. 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