比较基础的php面试题及答案-填空题


Posted in 面试题 onApril 26, 2014
填空题:
1.在PHP中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量__$_SERVER[PHP_SELF]__中;而链接到当前页面的URL记录在预定义变量__$_SERVER[HTTP_REFERER]__



2.执行程序段将输出__0__。

3.在HTTP 1.0中,状态码 401 的含义是____;如果返回“找不到文件”的提示,则可用 header 函数,其语句为____。

4.数组函数 arsort 的作用是__对数组进行逆向排序并保持索引关系__;语句 error_reporting(2047)的作用是__报告所有错误和警告__。

5.PEAR中的数据库连接字符串格式是____。

6.写出一个正则表达式,过虑网页上的所有JS/VBS脚本(即把scrīpt标记及其内容都去掉):preg_replace(“//si”, “newinfo”, $script);

7.以Apache模块的方式安装PHP,在文件http.conf中首先要用语句____动态装载PHP模块,然后再用语句____使得Apache把所有扩展名为php的文件都作为PHP脚本处理。
LoadModule php5_module “c:/php/php5apache2.dll” , AddType application/x-httpd-php .php,

8.语句 include 和 require 都能把另外一个文件包含到当前文件中,它们的区别是____;为了避免多次包含同一文件,可以用语句__require_once||include_once__来代替它们。

9.类的属性可以序列化后保存到 session 中,从而以后可以恢复整个类,这要用到的函数是____。

10.一个函数的参数不能是对变量的引用,除非在php.ini中把__allow_call_time_pass_reference boolean__设为on.

11.SQL中LEFT JOIN的含义是__自然左外链接__。如果 tbl_user记录了学生的姓名(name)和学号(ID),tbl_score记录了学生(有的学生考试以后被开除了,没有其记录)的学号(ID)

和考试成绩(score)以及考试科目(subject),要想打印出各个学生姓名及对应的的各科总成绩,则可以用SQL语句____。

12.在PHP中,heredoc是一种特殊的字符串,它的结束标志必须____。

编程题:
13.写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。
答:
function my_scandir($dir)
{
$files = array();
if ( $handle = opendir($dir) ) {
while ( ($file = readdir($handle)) !== false ) {
if ( $file != “..” && $file != “.” ) {
if ( is_dir($dir . “/” . $file) ) {
$files[$file] = scandir($dir . “/” . $file);
}else {
$files[] = $file;
}
}
}
closedir($handle);
return $files;
}
}

14.简述论坛中无限分类的实现原理。
答:
/*
数据表结构如下:
CREATE TABLE `category` (
`categoryID` smallint(5) unsigned NOT NULL auto_increment,
`categoryParentID` smallint(5) unsigned NOT NULL default ’0′,
`categoryName` varchar(50) NOT NULL default ”,
PRIMARY KEY (`categoryID`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;

INSERT INTO `category` ( `categoryParentID`, `categoryName`) VALUES
(0, ‘一级类别’),
(1, ‘二级类别’),
(1, ‘二级类别’),
(1, ‘二级类别’),
(2, ‘三级类别’),
(2, ’333332′),
(2, ’234234′),
(3, ‘aqqqqqd’),
(4, ‘哈哈’),
(5, ’66333666′);

*/

//指定分类id变量$category_id,然后返回该分类的所有子类
//$default_category为默认的选中的分类
function Get_Category($category_id = 0,$level = 0, $default_category = 0)
{
global $DB;
$sql = “SELECT * FROM category ORDER BY categoryID DESC”;
$result = $DB->query( $sql );
while ($rows = $DB->fetch_array($result))
{
$category_array[$rows[categoryParentID]][$rows[categoryID]] = array(‘id’ => $rows[categoryID], ‘parent’ => $rows[categoryParentID], ‘name’ => $rows

[categoryName]);
}
if (!isset($category_array[$category_id]))
{
return “”;
}
foreach($category_array[$category_id] AS $key => $category)
{
if ($category[id] == $default_category)
{
echo “ }else
{
echo “ }

if ($level > 0)
{
echo “>” . str_repeat( ” “, $level ) . ” ” . $category[name] . “\n”;
}
else
{
echo “>” . $category[name] . “\n”;
}
Get_Category($key, $level + 1, $default_category);
}
unset($category_array[$category_id]);
}

/*
函数返回的数组格式如下所示:
Array
(
[1] => Array ( [id] => 1 [name] => 一级类别 [level] => 0 [ParentID] => 0 )
[4] => Array ( [id] => 4 [name] => 二级类别 [level] => 1 [ParentID] => 1 )
[9] => Array ( [id] => 9 [name] => 哈哈 [level] => 2 [ParentID] => 4 )
[3] => Array ( [id] => 3 [name] => 二级类别 [level] => 1 [ParentID] => 1 )
[8] => Array ( [id] => 8 [name] => aqqqqqd [level] => 2 [ParentID] => 3 )
[2] => Array ( [id] => 2 [name] => 二级类别 [level] => 1 [ParentID] => 1 )
[7] => Array ( [id] => 7 [name] => 234234 [level] => 2 [ParentID] => 2 )
[6] => Array ( [id] => 6 [name] => 333332 [level] => 2 [ParentID] => 2 )
[5] => Array ( [id] => 5 [name] => 三级类别 [level] => 2 [ParentID] => 2 )
[10] => Array ( [id] => 10 [name] => 66333666 [level] => 3 [ParentID] => 5 )
)
*/
//指定分类id,然后返回数组
function Category_array($category_id = 0,$level=0)
{
global $DB;
$sql = “SELECT * FROM category ORDER BY categoryID DESC”;
$result = $DB->query($sql);
while ($rows = $DB->fetch_array($result))
{
$category_array[$rows[categoryParentID]][$rows[categoryID]] = $rows;
}

foreach ($category_array AS $key=>$val)
{
if ($key == $category_id)
{
foreach ($val AS $k=> $v)
{
$options[$k] =
array(
‘id’ => $v[categoryID], ‘name’ => $v[categoryName], ‘level’ => $level, ‘ParentID’=>$v[categoryParentID]
);

$children = Category_array($k, $level+1);

if (count($children) > 0)
{
$options = $options + $children;
}
}
}
}
unset($category_array[$category_id]);
return $options;
}

?>


class cate
{

function Get_Category($category_id = 0,$level = 0, $default_category = 0)
{
echo $category_id;
$arr = array(
’0′ => array(
’1′ => array(‘id’ => 1, ‘parent’ => 0, ‘name’ => ’1111′),
’2′ => array(‘id’ => 2, ‘parent’ => 0, ‘name’ => ’2222′),
’4′ => array(‘id’ => 4, ‘parent’ => 0, ‘name’ => ’4444′)
),
’1′ => array(
’3′ => array(‘id’ => 3, ‘parent’ => 1, ‘name’ => ’333333′),
’5′ => array(‘id’ => 5, ‘parent’ => 1, ‘name’ => ’555555′)
),

’3′ => array(
’6′ => array(‘id’ => 6, ‘parent’ => 3, ‘name’ => ’66666′),
’7′ => array(‘id’ => 7, ‘parent’ => 3, ‘name’ => ’77777′)
),
’4′ => array(
’8′ => array(‘id’ => 8, ‘parent’ => 4, ‘name’ => ’8888′),
’9′ => array(‘id’ => 9, ‘parent’ => 4, ‘name’ => ’9999′)
)
);

if (!isset($arr[$category_id]))
{
return “”;
}

foreach($arr[$category_id] AS $key => $cate)
{
if ($cate[id] == $default_category)
{
$txt = “ }else{
$txt = “ }

if ($level > 0)
{
$txt1 = “>” . str_repeat( “-”, $level ) . ” ” . $cate[name] . “\n”;
}else{
$txt1 = “>” . $cate[name] . “\n”;
}
$val = $txt.$txt1;
echo $val;
self::Get_Category($key, $level + 1, $default_category);
}

}

function getFlush($category_id = 0,$level = 0, $default_category = 0)
{

ob_start();

self::Get_Category($category_id ,$level, $default_category);

$out = ob_get_contents();

ob_end_clean();
return $out;
}
}
$id =$_GET[id];
echo “”;
?>

Tags in this post...

面试题 相关文章推荐
mysql_pconnect()和mysql_connect()有什么区别
May 25 面试题
J2SDK1.5与J2SDK5.0有什么区别
Sep 19 面试题
JAVA和C++的区别
Oct 06 面试题
用缩写的指针比较"if(p)" 检查空指针是否可靠?如果空指针的内部表达不是0会怎么样?
Jan 05 面试题
一个SQL面试题
Aug 21 面试题
网上常见的一份Linux面试题(多项选择部分)
Feb 07 面试题
介绍一下Linux中的链接
Jun 05 面试题
软件缺陷的分类都有哪些
Aug 22 面试题
你所在的项目是如何确定版本号的
Dec 28 面试题
如果Session Bean得Remove方法一直都不被调用会怎么样
Jul 14 面试题
如何执行一个shell程序
Nov 23 面试题
比较基础的php面试题及答案-编程题
Oct 14 #面试题
PHP中如何创建和修改数组
May 02 #面试题
PHP面试题集
Dec 18 #面试题
一些PHP的面试题
May 06 #面试题
几道PHP面试题
Apr 14 #面试题
PHP如何防止SQL注入
May 03 #面试题
几道PHP的面试题
May 19 #面试题
You might like
杏林同学录(九)
2006/10/09 PHP
js下函数般调用正则的方法附代码
2008/06/22 PHP
PHP获取网址的顶级域名函数代码
2012/09/24 PHP
PHP获取当前url的具体方法全面解析
2013/11/26 PHP
使用php方法curl抓取AJAX异步内容思路分析及代码分享
2014/08/25 PHP
举例讲解PHP面对对象编程的多态
2015/08/12 PHP
PHP计算当前坐标3公里内4个角落的最大最小经纬度实例
2016/02/26 PHP
php微信公众号开发之现金红包
2018/04/16 PHP
PHP基于curl模拟post提交json数据示例
2018/06/22 PHP
PHP array_reduce()函数的应用解析
2018/10/28 PHP
js有关元素内容操作小结
2011/12/20 Javascript
JavaScript中的无阻塞加载性能优化方案
2014/10/10 Javascript
jquery实现适用于门户站的导航下拉菜单效果代码
2015/08/24 Javascript
每天一篇javascript学习小结(Function对象)
2015/11/16 Javascript
JS从一组数据中找到指定的单条数据的方法
2016/06/02 Javascript
深入了解JavaScript的逻辑运算符(与、或)
2016/12/20 Javascript
基于JavaScript实现自定义滚动条
2017/01/25 Javascript
使用grunt合并压缩js和css文件的方法
2017/03/02 Javascript
vue.js国际化 vue-i18n插件的使用详解
2017/07/07 Javascript
使用 Node.js 实现图片的动态裁切及算法实例代码详解
2018/09/29 Javascript
jquery实现鼠标悬浮弹出气泡提示框
2020/12/23 jQuery
[05:46]2018完美盛典-《同梦共竞》
2018/12/17 DOTA
Python Cookie 读取和保存方法
2018/12/28 Python
python实现词法分析器
2019/01/31 Python
pycharm部署、配置anaconda环境的教程
2020/03/24 Python
Python调用Redis的示例代码
2020/11/24 Python
Python+kivy BoxLayout布局示例代码详解
2020/12/28 Python
HTML5时代CSS设置漂亮字体取代图片
2014/09/04 HTML / CSS
使用HTML5 Canvas API中的clip()方法裁剪区域图像
2016/03/25 HTML / CSS
租租车:国际租车、美国租车、欧洲租车、特价预订国外租车(中文服务)
2018/03/28 全球购物
经贸日语毕业生自荐信
2013/11/03 职场文书
领导接待方案
2014/03/13 职场文书
2016年教育局“我们的节日——端午节”主题活动总结
2016/04/01 职场文书
MySQL系列之九 mysql查询缓存及索引
2021/07/02 MySQL
Go语言编译原理之变量捕获
2022/08/05 Golang
CentOS7设置ssh服务以及端口修改方式
2022/12/24 Servers