Collection of classic PHP interview questions, collection of classic PHP test questions_PHP tutorial

WBOY
Release: 2016-07-13 10:02:12
Original
1097 people have browsed it

Collection of classic PHP interview questions, collection of classic PHP test questions

This article analyzes classic PHP interview questions in more detail. Share it with everyone for your reference. The details are as follows:

I did some PHP questions on the Internet, and I have reached this point without realizing it...posting the answers for reference.

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

$a = date("Y-m-d H:i:s", strtotime("-1 day"));
print_r($a);
Copy after login

2. The difference between echo(), 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 strings, not structures
print_r can print out the structure
For example

$arr = array("key"=>"value");
print_r($arr);
Copy after login

3. A template that allows HTML and PHP to be used separately (1 point)
smarty,phplib

4. What tools are used for version control? (1 point)
svn,git,cvs

5. How to implement string flipping? (3 points)
English:
strrev($a)
Chinese or other text:
Chinese: GB2312, the code is encoded using GB2312

<&#63;php 
function reverse($str)
{
 $ret = ""; 
 len=mbstrwidth(str,"GB2312");
 for(i=0;i< len;i++)
 {
 arr[]=mbsubstr(str, $i, 1, "GB2312");
 }
 return implode("", array_reverse($arr));
}
print_r(reverse("你好"));
Copy after login

6. Methods to optimize MYSQL database. (4 points, write more and get more)
In terms of sentences:
1 Use indexes to increase query efficiency
2 Optimize query statements and improve index hit rate
Database involved:
1 Construct sub-databases and sub-tables to improve the storage and expansion capabilities of the database
2 Use different storage engines as needed

7. What does PHP mean (get 1 point)
HyperText Preprocessing Language
Hypertext PreProcessor

8. What is the function of MYSQL to obtain the current time?, and the function of formatting date is (2 points)

CURRENT_TIMESTAMP()
DATE_FORMAT()
select DATE_FORMAT("2011-11-21 10:10:10", "%Y-%m-%d");
Copy after login

9. A method to intercept Chinese text strings without garbled characters. (3 points)

mb_substr($str, 1, 1, "GB2312");
Copy after login

10. Have you ever used version control software? If so, what is the name of the version control software you used? (1 point)
svn
git

11. Have you ever used a template engine? If so, what is the name of the template engine you used? (1 point)
smarty

12. Please briefly describe your most proud development work (4 points)
XXX

13. For websites with high traffic, what methods do you use to solve the traffic problem? (4 points)
1 Use cache effectively to increase cache hit rate
2 Use load balancing
3 Use CDN to store and accelerate static files
4 ideas to reduce database usage
5 Check where the statistical bottlenecks are

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 include and require statements? To avoid including the same file multiple times, you can replace them with (?) statements? (2 points)
On failure:
include generates a warning, while require generates an 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.bkjia.com/index.html, how to get its content? ($1 point)
file_get_contents
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");
Copy after login

fast CGI:

header("Status: 404 Not Found");
Copy after login

19. In PHP, heredoc is a special string, and its end mark must be? (1 point)
Appear in pairs

$a = <<EOD
good test
EOD;
Copy after login

20. Talk about the advantages and disadvantages of asp, 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: show
control: Receive and judge processing input

22. Write the SQL of the names of the ten people with the most posts, using the following table: members (id, username, posts, pass, email) (2 points)
select top 10 id,username from members order by posts desc

23. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference? (2 points)
& means passing a reference
Passing parameters by reference in a function will change the parameters
Generally, you can consider using references

when there are multiple output parameters.

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&#8722;z0&#8722;9\.&#8722;]+)@([\da&#8722;z\.&#8722;]+)\.([a&#8722;z\.]2,6)" ; //正则
return preg_match(regex,str)
Copy after login

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

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

28. What is the function to pop up a dialog box in a JS form? What is the function to get input focus? (2 points)

alert()
confirm()
promopt()
focus()

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

window.location.href="#"
<script src="#"></script>
Copy after login

30. What is the difference between foo() and @foo()? (1 point)
@ stands for all warnings and is ignored

31、如何声明一个名为”myclass”的没有方法和属性的类? (1分)

class myclass
{
}
Copy after login

32、如何实例化一个名为”myclass”的对象?(1分)

$myclass = new myclass();
Copy after login

33、你如何访问和设置一个类的属性? (2分)

<&#63;php
class A
{
 public $name = "A";
}
$a = new A();
n=a->name;
print_r($n);
Copy after login

34、mysql_fetch_row() 和mysql_fetch_array之间有什么区别? (1分)
mysql_fetch_array() 是 mysql_fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。

<&#63;php
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);
Copy after login

35、GD库是做什么用的? (1分)

动态的开放的图片处理库

36、指出一些在PHP输入一段HTML代码的办法。(1分)

echo "{html}"
echo <<EOD
{html}
EOD;
Copy after login

37、下面哪个函数可以打开一个文件,以对文件进行读和写操作?(1分) c
(a) fget() (b) file_open() (c) fopen() (d) open_file()

38、下面哪个选项没有将 john 添加到users 数组中? (1分) b
(a) $users[] = ‘john';
(b) array_add($users,'john');
(c) array_push($users,‘john');
(d) $users ||= ‘john';

39、下面的程序会输入是否?(1分) 10

$num = 10;
function multiply(){
num=num * 10;
}
multiply();
echo $num;
&#63;>
Copy after login

40、使用php写一段简单查询,查出所有姓名为“张三”的内容并打印出来 (2分)
表名 UserName Tel Content Date
 张三 13333663366 大专毕业 2006-10-11
 张三 13612312331 本科毕业 2006-10-15
 张四 021-55665566 中专毕业 2006-10-15
请根据上面的题目完成代码:

$mysql_db=mysql_connect("local","root","pass");
@mysql_select_db("DB",$mysql_db);
$sql = sprintf("select * from %s where UserName = '%s'", 
 "表名", 
 "张三");
values=mysqlquery(sql);
while(item=mysqlfetchqueryarray(values))
{
 echo sprintf("用户名:%s, 电话 %s, 学历: %s, 毕业日期: %s", 
 item['UserName'],item['Tel'], item['Content'],item['Date']
 );
}
Copy after login

41、如何使用下面的类,并解释下面什么意思?(3)

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;
Copy after login

将num进行MD5编码之后生成的32位字符串a1和"En"联系起来之后再进行一次MD5编码

42、写出 SQL语句的格式 : 插入 ,更新 ,删除 (4分)
表名 UserName Tel Content Date
   张三 13333663366 大专毕业 2006-10-11
   张三 13612312331 本科毕业 2006-10-15
   张四 021-55665566 中专毕业 2006-10-15
(a) 有一新记录(小王 13254748547 高中毕业 2007-05-06)请用SQL语句新增至表中
insert into 表名 values('小王', '13254748547', '高中毕业', '2007-05-06')
(b) 请用sql语句把张三的时间更新成为当前系统时间
update 表名 set Date = GETDATE() where UserName = "张三"
(c) 请写出删除名为张四的全部记录
delete from 表明 where UserName = "张四"

43、请写出数据类型(int char varchar datetime text)的意思; 请问varchar和char有什么区别(2分)
int 整型
char 存储定长
varchar 存储变长
datetime 时间
text 存储变长的
varchar是变长
char(20) 定长

44、MySQ自增类型(通常为表ID字段)必需将其设为(?)字段(1分)
auto_increment
45、写出以下程序的输出结果 (1分)

$b=201;
$c=40;
a=b>$c&#63;4:5;
echo $a;
Copy after login

46、检测一个变量是否有设置的函数是否?是否为空的函数是?(2分)
isset()
empty()

47、取得查询结果集总数的函数是?(1分)

mysql_num_rows()
Copy after login

48、$arr = array('james', 'tom', 'symfony'); 请打印出第一个元素的值 (1分)

print_r($arr[0]);
reset($arr);
print_r(current($arr));
print_r(array_shift($arr));
Copy after login

49、请将41题的数组的值用','号分隔并合并成字串输出(1分)
implode

50、a='abcdef';请取出a的值并打印出第一个字母(1分)

$a[0];
substr($a, 0, 1);
Copy after login

51、PHP可以和sql server/oracle等数据库连接吗?(1分)
可以
有现成的库

52、请写出PHP5权限控制修饰符(3分)
public
private
protected

53、请写出php5的构造函数和析构函数(2分)

public function __construct()
{
}
public function __destruct()
{
}
Copy after login

编程题:

1. 写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名
例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php

<&#63;php
$url = "http://www.sina.com.cn/abc/de/fg.php&#63;id=1";
arr=parseurl(url);
pathArr=pathinfo(arr['path']);
print_r($pathArr['extension']);
Copy after login

3. 写一个函数,算出两个文件的相对路径
如 $a = '/a/b/c/d/e.php';
$b = '/a/b/12/34/c.php';
计算出 b相对于a 的相对路径应该是 http://www.bkjia.com/12/34/c.php将添上

<&#63;php
$a = '/a/b/c/d/e.php';
$b = '/a/b/12/34/c.php';
//获取path相对于conpath的相对路径
function sGetRelativePath(path,conpath)
{
 pathArr=explode("/",path);
 conpathArr=explode("/",conpath);
 $dismatchlen = 0;
 for(i=0;i < count(pathArr);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));
Copy after login

3.写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。

<&#63;php
function aGetAllFile($folder)
{
 $aFileArr = array();
 if(is_dir($folder))
 {
 handle=opendir(folder);
 while((file=readdir(handle)) !== false)
 {
  //如果是.或者..则跳过
  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));
Copy after login

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/970855.htmlTechArticle Collection of classic PHP interview questions, collection of classic PHP test questions. This article analyzes classic PHP interview questions in more detail. Share it with everyone for your reference. The details are as follows: I did some php questions on the Internet...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template