您好,欢迎访问一九零五行业门户网

转php面试题及我的答案(二)

1.在php中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量(1)中;而链接到当前页面的的前一页面url记录在预定义变量(2)中 ? php // 本页地址,script_name也可以:php/test.php echo $_server [ ' php_self ' ] . br/ ; // 链接到当前页面的
1.在php中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量(1)中;而链接到当前页面的的前一页面url记录在预定义变量(2)中
php
//本页地址,script_name也可以:php/test.php
echo $_server['php_self'].
;
//链接到当前页面的前一页面的 url 地址:
echo $_server['http_referer'].
;
//其它的见参考手册:语言参考》变量》预定义变量
//前执行脚本的绝对路径名:d:inetpubwwwrootphp est.php 
echo $_server[script_filename].
;
//正在浏览当前页面用户的 ip 地址:127.0.0.1
echo $_server[remote_addr].
;
//查询(query)的字符串(url 中第一个问号 ? 之后的内容):id=1&bi=2
echo $_server[query_string].
;
//当前运行脚本所在的文档根目录:d:inetpubwwwroot
echo $_server[document_root].
;
?>
2.执行程序段将输出__。
php
//参考手册》语言参考》运算符》算术运算符》%为取模运算,输出0
echo 8%(-2).
;
//取模 $a % $b 在 $a 为负值时的结果也是负值。输出-2
echo ((-8)%3).
;
//输出2
echo (8%(-3)).
;
?>
3.在http 1.0中,状态码 401 的含义是____;如果返回“找不到文件”的提示,则可用 header 函数,其语句为____。
答:401表示未授权;header(http/1.0 404 not found);[见参考手册》函数参考》http函数》header]
4.数组函数 arsort 的作用是____;语句 error_reporting(2047)的作用是____。
答:arsort:对数组进行逆向排序并保持索引关系 error_reporting(2047)的作用是:report all errors and warnings
5.写出一个正则表达式,过虑网页上的所有js/vbs脚本(即把script标记及其内容都去掉):
php
$script=以下内容不显示:;
echo preg_replace(//si, 替换内容, $script);
?>
6.以apache模块的方式安装php,在文件http.conf中首先要用语句____动态装载php模块,
然后再用语句____使得apache把所有扩展名为php的文件都作为php脚本处理。
答:loadmodule php5_module c:/php/php5apache2.dll;addtype application/x-httpd-php .php
见参考手册》目录》ii. 安装与配置》6. windows 系统下的安装》microsoft windows 下的 apache 2.0.x
7.语句 include 和 require 都能把另外一个文件包含到当前文件中,它们的区别是____;为了避免多次包含同一文件,可以用语句____来代替它们。
答:在如何处理失败时,include() 产生一个警告而 require() 则导致一个致命错误;require_once()/include_once()
8.一个函数的参数不能是对变量的引用,除非在php.ini中把____设为on.
答:allow_call_time_pass_reference boolean :是否启用在函数调用时强制参数被按照引用传递, 见参考手册》附录g
9.sql 中left join的含义是__,如果 tbl_user记录了学生的姓名(name)和学号(id),
tbl_score记录了学生(有的学生考试以后被开除了,没有其记录)的学号(id)和考试成绩(score)以及考试科目(subject),要想打印出各个学生姓名及对应的的各科总成绩,则可以用sql语句____.
答:自然左外连接
create database phpinterview;
use phpinterview
create table tbl_user
(
   id                             int                            not null,
   name                           varchar(50)                    not null,
   primary key (id)
);
create table tbl_score
(
   id                             int                            not null,
   score                          dec(6,2)                       not null,
   subject                        varchar(20)                    not null
);
insert into tbl_user (id, name) values (1, 'beimu');
insert into tbl_user (id, name) values (2, 'aihui');
insert into tbl_score (id, score, subject) values (1, 90, '语文');
insert into tbl_score (id, score, subject) values (1, 80, '数学');
insert into tbl_score (id, score, subject) values (2, 86, '数学');
insert into tbl_score (id, score, subject) values (2, 96, '语文');
select a.id,sum(b.score) as sumscore
from tbl_user a left join tbl_score b
on a.id=b.id
group by a.id
10.  在php中,heredoc是一种特殊的字符串,它的结束标志必须____
答:结束标识符所在的行不能包含任何其它字符除;
11.写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。
php
function my_scandir($dir)
{
    $files=array();
    if(is_dir($dir))
    {
        if($handle=opendir($dir))
        {
            while(($file=readdir($handle))!==false)
            {
                if($file!=. && $file!=..)
                {
                    if(is_dir($dir./.$file))
                    {
                        $files[$file]=my_scandir($dir./.$file);
                    }
                    else
                    {
                        $files[]=$dir./.$file;
                    }
                }
            }
            closedir($handle);
            return $files;
        }        
    }    
}
print_r(my_scandir(d:program filesinternet explorermui));
?>
参考文件:
1.http://blog.chinaunix.net/u/21675/showart_153169.html
其它类似信息

推荐信息