zoukankan      html  css  js  c++  java
  • 最全最详细的PHP面试题(带有答案)

    这篇文章介绍的内容是关于最全最详细的PHP面试题(带有答案),有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

    1、__FILE__表示什么意思?(5分)
    文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,__FILE__ 总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。
    2、如何获取客户端的IP地址?(5分)

    1
    $_SERVER[‘REMOTE_ADDR’]

    3、写出使用header函数跳转页面的语句(5分)

    1
    Header(‘location:index.php’);

    4、$str是一段html文本,使用正则表达式去除其中的所有js脚本(5分)

    1
    2
    $pattern = ‘/<script.*>.+</script>/’;
    Preg_replace($pattern,’’,$str);

    5、写出将一个数组里的空值去掉的语句(5分)

    1
    $arr = array(‘’,1,2,3,’’,19);

    第一种方法:

    1
    2
    3
    4
    5
    6
    $array1 = array('  ',1,'',2,3);
    print_r(array_filter($array1, "del"));
    function del($var)
    {
           return(trim($var));
    }

    第二种方法:

    1
    2
    3
    $arr=array("",1,2,3,"");
    $ptn="/S+/i";
    print_r(preg_grep($ptn,$arr));

    6、写出获取当前时间戳的函数,及打印前一天的时间的方法(格式:年-月-日 时:分:秒) (5分)

    1
    2
    Time();
    Date(“Y-m-d H:i:s”,Strtotime(“-1 day”));

    7、写出php进行编码转换的函数(5分)

    1
    Iconv(‘utf-8’,’gb2312’,$str);

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

    1
    $arr = explode(“,”,$str);

    9、serialize() /unserialize()函数的作用(5分)
    serialize()和unserialize()在php手册上的解释是:
    serialize — 产生一个可存储的值的表示,返回值为字符串,此字符串包含了表示 value 的字节流,不丢失其类型和结构,可以存储于任何地方。
    unserialize — 从已存储的表示中创建 PHP 的值
    具体用法:

    1
    2
    $arr = array(“测试1″,”测试2″,”测试3″);//数组
    $sarr = serialize($arr);//产生一个可存储的值(用于存储)

    //用任意方法(例如:你要是吧$sarr存在一个文本文件中你就可以用file_get_contents取得)得到存储的值保存在$newarr中;

    1
    $unsarr=unserialize($newarr);//从已存储的表示中创建 PHP 的值

    10、写出一个函数,参数为年份和月份,输出结果为指定月的天数(5分)

    1
    2
    3
    Function day_count($year,$month){
    Echo date(“t”,strtotime($year.”-”.$month.”-1”));
    }

    11、一个文件的路径为/wwwroot/include/page.class.php,写出获得该文件扩展名的方法(5分)

    1
    2
    $arr = pathinfo(“/wwwroot/include/page.class.php”);
    $str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));

    12、你使用过哪种PHP的模板引擎?(5分)
    Smarty,thinkphp自带的模板引擎
    13、请简单写一个类,实例化这个类,并写出调用该类的属性和方法的语句(5分)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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的所有记录打印结果,并统计出查询出的结果总数。(5分)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?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表里插入与新加入的记录关联的两条记录(5分)
    2)获取score表里uid为2的用户score最高的5条记录(5分)
    3)使用联合查询获取name为“张三”的用户的总分数(5分)
    4)删除name为“李四”的用户,包括分数记录(5分)
    5)清空score表(5分)
    6)删除user表(5分)

    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;

     

    http://www.php.cn/php-weizijiaocheng-393700.html

  • 相关阅读:
    1041 考试座位号
    1040 有几个PAT
    1039 到底买不买
    1038 统计同成绩学生
    1037 在霍格沃茨找零钱
    1036 跟奥巴马一起编程
    1035 插入与归并
    vue-router--路由传参
    vue-router--路由原理
    vuex--在computed中使用
  • 原文地址:https://www.cnblogs.com/youxianyen/p/9548109.html
Copyright © 2011-2022 走看看