人人范文网 范文大全

PHP程序员面试题经典及答案集锦

发布时间:2020-03-02 16:51:32 来源:范文大全 收藏本文 下载本文 手机版

都是经典

基础题: 1.表单中 get与post提交方法的区别? 答:get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息.2.seion与cookie的区别? 答:seion:储存用户访问的全局唯一变量,存储在服务器上的php指定的目录中的(seion_dir)的位置进行的存放

cookie:用来存储连续訪問一个頁面时所使用,是存储在客户端,对于Cookie来说是存储在用户WIN的Temp目录中的。

两者都可通过时间来设置时间长短

3.数据库中的事务是什么? 答:事务(transaction)是作为一个单元的一组有序的数据库操作。如果组中的所有操作都成功,则认为事务成功,即使只有一个操作失败,事务也不成功。如果所有操作完成,

事务则提交,其修改将作用于所有其他数据库进程。如果一个操作失败,则事务将回滚,该事务所有操作的影响都将取消。

简述题:

1、用PHP打印出前一天的时间格式是2006-5-10 22:21:21(2分) 答:echo date(\'Y-m-d H:i:s\', strtotime(\'-1 days\'));

2、echo(),print(),print_r()的区别(3分) 答:echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用) print() 只能打印出简单类型变量的值(如int,string) print_r() 可以打印出复杂类型变量的值(如数组,对象) echo 输出一个或者多个字符串

3、能够使HTML和PHP分离开使用的模板(1分) 答:Smarty,Dwoo,TinyButStrong,Template Lite,Savant,phemplate,XTemplate

5、使用哪些工具进行版本控制?(1分) 答:cvs,svn,v;

6、如何实现字符串翻转?(3分) 答:echo strrev($a);

7、优化MYSQL数据库的方法。(4分,多写多得) 答:

1、选取最适用的字段属性,尽可能减少定义字段长度,尽量把字段设置NOT NULL,例如\'省份,性别\',最好设置为ENUM

2、使用连接(JOIN)来代替子查询: a.删除没有任何订单客户:DELETE FROM customerinfo WHERE customerid NOT in(SELECT customerid FROM orderinfo) b.提取所有没有订单客户:SELECT FROM customerinfo WHERE customerid NOT in(SELECT customerid FROM orderinfo) c.提高b的速度优化:SELECT FROM customerinfo LEFT JOIN orderid customerinfo.customerid=orderinfo.customerid WHERE orderinfo.customerid IS NULL

3、使用联合(UNION)来代替手动创建的临时表

a.创建临时表:SELECT name FROM `nametest` UNION SELECT username FROM `nametest2`

4、事务处理: a.保证数据完整性,例如添加和修改同时,两者成立则都执行,一者失败都失败

mysql_query(\"BEGIN\"); mysql_query(\"INSERT INTO customerinfo (name) VALUES (\'$name1\')\"; mysql_query(\"SELECT * FROM `orderinfo` where customerid=\".$id\"); mysql_query(\"COMMIT\");

5、锁定表,优化事务处理: a.我们用一个 SELECT 语句取出初始数据,通过一些计算,用 UPDATE 语句将新值更新到表中。

包含有 WRITE 关键字的 LOCK TABLE 语句可以保证在 UNLOCK TABLES 命令被执行之前,

不会有其它的访问来对 inventory 进行插入、更新或者删除的操作 mysql_query(\"LOCK TABLE customerinfo READ, orderinfo WRITE\"); mysql_query(\"SELECT customerid FROM `customerinfo` where id=\".$id); mysql_query(\"UPDATE `orderinfo` SET ordertitle=\'$title\' where customerid=\".$id); mysql_query(\"UNLOCK TABLES\");

6、使用外键,优化锁定表

a.把customerinfo里的customerid映射到orderinfo里的customerid, 任何一条没有合法的customerid的记录不会写到orderinfo里 CREATE TABLE customerinfo ( customerid INT NOT NULL, PRIMARY KEY(customerid) )TYPE = INNODB; CREATE TABLE orderinfo ( orderid INT NOT NULL, customerid INT NOT NULL, PRIMARY KEY(customerid,orderid), FOREIGN KEY (customerid) REFERENCES customerinfo (customerid) ON DELETE CASCADE )TYPE = INNODB; 注意:\'ON DELETE CASCADE\',该参数保证当customerinfo表中的一条记录删除的话同时也会删除order 表中的该用户的所有记录,注意使用外键要定义事务安全类型为INNODB;

7、建立索引: a.格式: (普通索引)-> 创建:CREATE INDEX ON tablename (索引字段) 修改:ALTER TABLE tablename ADD INDEX [索引名] (索引字段) 创表指定索引:CREATE TABLE tablename([...],INDEX[索引名](索引字段)) (唯一索引)-> 创建:CREATE UNIQUE ON tablename (索引字段) 修改:ALTER TABLE tablename ADD UNIQUE [索引名] (索引字段) 创表指定索引:CREATE TABLE tablename([...],UNIQUE[索引名](索引字段)) (主键)-> 它是唯一索引,一般在创建表是建立,格式为: CREATA TABLE tablename ([...],PRIMARY KEY[索引字段])

8、优化查询语句

a.最好在相同字段进行比较操作,在建立好的索引字段上尽量减少函数操作

例子1: SELECT * FROM order WHERE YEAR(orderDate)=\"good\" and name

8、PHP的意思(送1分) 答:PHP是一个基于服务端来创建动态网站的脚本语言,您可以用PHP和HTML生成网站主页

9、MYSQL取得当前时间的函数是?,格式化日期的函数是(2分) 答:now(),date()

10、实现中文字串截取无乱码的方法。(3分) 答:function GBsubstr($string, $start, $length) { if(strlen($string)>$length){ $str=null; $len=$start+$length; for($i=$start;$i0xa0){ $str.=substr($string,$i,2); $i++; }else{ $str.=substr($string,$i,1); } } return $str.\'...\'; }else{ return $string; } }

11、您是否用过版本控制软件? 如果有您用的版本控制软件的名字是?(1分)

12、您是否用过模板引擎? 如果有您用的模板引擎的名字是?(1分) 答:用过,smarty

13、请简单阐述您最得意的开发之作(4分) 答:信息分类

14、对于大流量的网站,您采用什么样的方法来解决访问量问题?(4分) 答:确认服务器硬件是否足够支持当前的流量,数据库读写分离,优化数据表, 程序功能规则,禁止外部的盗链,控制大文件的下载,使用不同主机分流主要流量

15、用PHP写出显示客户端IP与服务器IP的代码1分) 答:打印客户端IP:echo $_SERVER[‘REMOTE_ADDR’]; 或者: getenv(\'REMOTE_ADDR\'); 打印服务器IP:echo gethostbyname(\"www.daodoc.com/abc/de/fg.php?id=1 需要取出 php 或 .php 答案1: function getExt($url){ $arr = parse_url($url);

$file = basename($arr[\'path\']); $ext = explode(\".\",$file); return $ext[1]; } 答案2: function getExt($url) { $url = basename($url); $pos1 = strpos($url,\".\"); $pos2 = strpos($url,\"?\"); if(strstr($url,\"?\")){ return substr($url,$pos1 + 1,$pos21); } else { return substr($url,$pos1); } }

2.在 HTML 语言中,页面头部的 meta 标记可以用来输出文件的编码格式,以下是一个标准的 meta 语句

请使用 PHP 语言写一个函数,把一个标准 HTML 页面中的类似 meta 标记中的 charset 部分值改为 big5

请注意:

1.需要处理完整的 html 页面,即不光此 meta 语句

2.忽略大小写

3.\' 和 \" 在此处是可以互换的

4.\'Content-Type\' 两侧的引号是可以忽略的,但 \'text/html; charset=gbk\' 两侧的不行

5.注意处理多余空格

3.写一个函数,算出两个文件的相对路径

如 $a = \'/a/b/c/d/e.php\';

$b = \'/a/b/12/34/c.php\';

计算出 $b 相对于 $a 的相对路径应该是 ../../c/d将()添上 答:function getRelativePath($a, $b) { $returnPath = array(dirname($b)); $arrA = explode(\'/\', $a); $arrB = explode(\'/\', $returnPath[0]); for ($n = 1, $len = count($arrB); $n

$returnPath = array_merge($returnPath, array_slice($arrA, $n)); return implode(\'/\', $returnPath); } echo getRelativePath($a, $b); 填空题: 1.在PHP中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量__$_SERVER[\'PHP_SELF\']__中;而链接到当前页面的URL记录在预定义变量__$_SERVER[\'HTTP_REFERER\']__ 中

2.执行程序段<?php echo 8%(-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.类的属性可以序列化后保存到 seion 中,从而以后可以恢复整个类,这要用到的函数是____。

10.一个函数的参数不能是对变量的引用,除非在php.ini中把__allow_call_time_pa_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.简述论坛中无限分类的实现原理。 答: <?php /* 数据表结构如下: 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 (!iet($category_array[$category_id])) { return \"\"; } foreach($category_array[$category_id] AS $key => $category) { if ($category[\'id\'] == $default_category) { echo \" 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; } ?> <?php cla 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 (!iet($arr[$category_id])) { return \"\"; }

foreach($arr[$category_id] AS $key => $cate) { if ($cate[\'id\'] == $default_category) { $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 \"\"; $c = new cate(); //$c->Get_Category(); $ttt= $c->getFlush($id,\'0\',\'3\'); echo $ttt; echo \"\"; ?>

PHP程序员面试题

PHP程序员面试题

PHP程序员面试题

php程序员面试题(附答案)

php程序员面试题(a卷 附答案)

php程序员面试题(b卷_附答案)

php程序员 一度搜索面试题

php工程师面试题及答案

PHP程序员

PHP面试题

PHP程序员面试题经典及答案集锦
《PHP程序员面试题经典及答案集锦.doc》
将本文的Word文档下载到电脑,方便编辑。
推荐度:
点击下载文档
点击下载本文文档