background image

PHP 面试题答案

1、求$a,$b,$c 三个数中的最大值和最小值(分)

echo max($a,$b,$c);
echo min($a,$b,$c);

2echo()print()print_r()的区别(分)

print()    

只 能 打 印 出 简 单 类 型 变 量 的 值 ( 如 int,string)  

print_r() 

可 以 打 印 出 复 杂 类 型 变 量 的 值 ( 如 数 组 , 对 象 )  

echo      输出一个或者多个字符串
3、防止 SQL 注入漏洞可以用哪些函数?(分)

addslashes()
mysql_escape_string()

正确回答 1 个即可

4、用 PHP 写出显示客户端 IP 与服务器 IP 的代码(分)
echo $_SERVER[‘REMOTE_ADDR’];

echo $_SERVER[‘SERVER_ADDR’];

5、用 PHP

 

打印出前一天的时间,格式例如 2006-5-10 22:21:2110 分)

strftime(“%Y-%m-%d %T”, strtotime(“-1 day”));

date(“Y-m-d H:i:s”, strtotime(“-1 day”));

正确回答 1 个即可

6、写一个函数,能够遍历一个文件夹下的所有文件和子文件夹(20 分)

function dir_recurse($dir) {
    $i = 1;

    if($handle = opendir($dir)) {
        while(false !== ($file = readdir($handle))) {

            if($file != "." && $file != ".." ) {
                if(is_dir($dir."/".$file) == true) {

                    $fullpath = $dir."/".$file;
                    dir_recurse($fullpath);

                    echo "$fullpath\n";
                    $i++;

                }else {
                    $fullpath = $dir."/".$file;

                    echo "$fullpath\n";
                    $i++;

                }
            }

        }
        closedir($handle);

    }
}

7、创 建文件 exer1,设置访 问权限为 rw-r--r--,现要增 加所有用 户的执行 权限

和同组用户的写权限,写出操作过程的命令(10 分)
touch exer1

chmod 644  exer1

增加权限
chmod a+x  exer1 
chmod g+w  exer1 

或者
chmod 775 exer1