最全最详细的PHP面试题(带有答案)

1、__FILE__表示什么意思?

文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,__FILE__ 总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。

2、如何获取客户端的IP地址?

$_SERVER[‘REMOTE_ADDR’]
3、写出使用header函数跳转页面的语句

Header(‘location:index.php’);
4、$str是一段html文本,使用正则表达式去除其中的所有js脚本

$pattern = ‘/<script.*>\.+<\/script>/’;
 
Preg_replace($pattern,’’,$str);
5、写出将一个数组里的空值去掉的语句

$arr = array(‘’,1,2,3,’’,19);
第一种方法:

$array1 = array('  ',1,'',2,3);
 
print_r(array_filter($array1, "del"));
 
function del($var)
 
{
 
       return(trim($var)); 
 
}
第二种方法:

$arr=array("",1,2,3,"");
 
$ptn="/\S+/i";
 
print_r(preg_grep($ptn,$arr));
6、写出获取当前时间戳的函数,及打印前一天的时间的方法(格式:年-月-日 时:分:秒) 

Time();
 
Date(“Y-m-d H:i:s”,Strtotime(“-1 day”));
7、写出php进行编码转换的函数

Iconv(‘utf-8’,’gb2312’,$str);
8、$str = “1,3,5,7,9,10,20”,使用什么函数可以把字符串str转化为包含各个数字的数组?

$arr = explode(“,”,$str);
9、serialize() /unserialize()函数的作用

serialize()和unserialize()在php手册上的解释是:

serialize — 产生一个可存储的值的表示,返回值为字符串,此字符串包含了表示 value 的字节流,不丢失其类型和结构,可以存储于任何地方。

unserialize — 从已存储的表示中创建 PHP 的值

具体用法:

$arr = array(“测试1″,”测试2″,”测试3″);//数组
 
$sarr = serialize($arr);//产生一个可存储的值(用于存储)
//用任意方法(例如:你要是吧$sarr存在一个文本文件中你就可以用file_get_contents取得)得到存储的值保存在$newarr中;

$unsarr=unserialize($newarr);//从已存储的表示中创建 PHP 的值
10、写出一个函数,参数为年份和月份,输出结果为指定月的天数

Function day_count($year,$month){
 
Echo date(“t”,strtotime($year.”-”.$month.”-1”));
 
}
11、一个文件的路径为/wwwroot/include/page.class.php,写出获得该文件扩展名的方法

$arr = pathinfo(“/wwwroot/include/page.class.php”);
 
$str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));
12、你使用过哪种PHP的模板引擎?

Smarty,thinkphp自带的模板引擎

13、请简单写一个类,实例化这个类,并写出调用该类的属性和方法的语句

Class myclass{
 
Public $aaa;
 
Public $bbb;
 
Public function myfun(){
 
Echo “this is my function”;
 
}
 
}
 
$myclass = new myclass();
 
$myclass->$aaa;
 
$myclass->myfun();
14、本地mysql数据库db_test里已建有表friend,数据库的连接用户为root,密码为123

friend表字段为:id,name,age,gender,phone,email

请使用php连接mysql,选择出friend表里age > 20的所有记录打印结果,并统计出查询出的结果总数。

<?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’];
 
….
 
}
15、以下有两个表

user表 字段id (int),name (varchar)

score表 字段uid (int),subject (varchar) ,score (int)

score表的uid字段与user表的id字段关联

要求写出以下的sql语句

1)在user表里新插入一条记录,在score表里插入与新加入的记录关联的两条记录

2)获取score表里uid为2的用户score最高的5条记录

3)使用联合查询获取name为“张三”的用户的总分数

4)删除name为“李四”的用户,包括分数记录

5)清空score表

6)删除user表

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;
以上就是最全最详细的PHP面试题(带有答案)的详细内容

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值