php面试题集及答案

WBOY
發布: 2016-07-25 08:53:45
原創
1270 人瀏覽過
  1. $a = date("y-m-d h:i:s", strtotime("-1 day"));
  2. print_r($a);
复制代码

2、echo(),print(),print_r()的区别(3分)

  1. echo 和print不是一个函数,是一个语言结构
  2. int print(string $arg), 只有一个参数
  3. echo arg1,arg2; 可以输出多个参数,返回void
  4. echo和print只能打印出string,不能打印出结构
  5. print_r能打印出结构
  6. 比如
  7. $arr = array("key"=>"value");
  8. print_r($arr);
复制代码

3、能够使html和php分离开使用的模板(1分) smarty,phplib 4、使用哪些工具进行版本控制?(1分) svn,git,cvs 5、如何实现字符串翻转?(3分) 英文: strrev($a) 中文或其他文字: 中文:gb2312, 代码是使用gb2312编码

  1. function reverse($str)
  2. {
  3. $ret = "";
  4. len=mbstrwidth(str,"gb2312");
  5. for(i=0;i {
  6. arr[]=mbsubstr(str, $i, 1, "gb2312");
  7. }
  8. return implode("", array_reverse($arr));
  9. }
  10. print_r(reverse("你好"));
复制代码

6、优化mysql数据库的方法。(4分,多写多得) 语句方面: 1 使用索引,增加查询效率 2 优化查询语句,提高索引命中率 数据库涉及方面: 1 构造分库分表,提高数据库的存储和扩展能力 2 根据需要使用不同的存储引擎 7、php的意思(送1分) 超级文本预处理语言 hypertext preprocessor 8、mysql取得当前时间的函数是?,格式化日期的函数是(2分)

  1. current_timestamp()
  2. date_format()
  3. select date_format("2011-11-21 10:10:10", "%y-%m-%d");
复制代码

9、实现中文字串截取无乱码的方法。(3分) mb_substr($str, 1, 1, "gb2312"); 10、您是否用过版本控制软件? 如果有您用的版本控制软件的名字是?(1分) svn git 11、您是否用过模板引擎? 如果有您用的模板引擎的名字是?(1分) smarty 12、请简单阐述您最得意的开发之作(4分) xxx 13、对于大流量的网站,您采用什么样的方法来解决访问量问题?(4分) 1 有效使用缓存,增加缓存命中率 2 使用负载均衡 3 对静态文件使用cdn进行存储和加速 4 想法减少数据库的使用 5 查看出现统计的瓶颈在哪里 14、用php写出显示客户端ip与服务器ip的代码1分) $_server["remote_addr"] $_server["server_addr"] 15、语句include和require的区别是什么?为避免多次包含同一文件,可用(?)语句代替它们? (2分) 在失败的时候: include产生一个warning,而require产生直接产生错误中断 require在运行前载入 include在运行时载入 require_once include_once 16、如何修改session的生存时间(1分). session_set_cookie_params 17、有一个网页地址, 比如脚本学堂主页: http://bbs.it-home.org/index.html,如何得到它的内容?($1分) file_get_contents curl 18、在http 1.0中,状态码401的含义是(?);如果返回“找不到文件”的提示,则可用 header 函数,其语句为(?);(2分) 未授权 header("http/1.0 404 not found"); fast cgi中: header("status: 404 not found"); 19、在php中,heredoc是一种特殊的字符串,它的结束标志必须?(1分) 成对出现 $a =

  1. $str = "jianfeng@126.com";
  2. regex="([a?z0?9\.?]+)@([\da?z\.?]+)\.([a?z\.]2,6)" ; //正则
  3. return preg_match(regex,str)
复制代码

26. 简述如何得到当前执行脚本路径,包括所得到参数。(2分) $argc --获取参数数量 $argv --获取参数列表 27.如何修改session的生存时间. (1分) session_set_cookie_params 28、js表单弹出对话框函数是?获得输入焦点函数是? (2分) alert() confirm() promopt() focus() 29、js的转向函数是?怎么引入一个外部js文件?(2分) window.location.href="#" 30、foo()和@foo()之间有什么区别?(1分) @代表所有warning忽略 31、如何声明一个名为”myclass”的没有方法和属性的类? (1分) class myclass { } 32、如何实例化一个名为”myclass”的对象?(1分) $myclass = new myclass(); 33、你如何访问和设置一个类的属性? (2分)

  1. class a
  2. {
  3. public $name = "a";
  4. }
  5. $a = new a();
  6. n=a->name;
  7. print_r($n);
复制代码

34、mysql_fetch_row() 和mysql_fetch_array之间有什么区别? (1分) mysql_fetch_array() 是 mysql_fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。

  1. mysql_connect("localhost", "mysql_user", "mysql_password") or
  2. die("could not connect: " . mysql_error());
  3. mysql_select_db("mydb");
  4. $result = mysql_query("select id, name from mytable");
  5. while (row=mysqlfetcharray(result, mysql_assoc)) {
  6. printf ("id: %s name: %s", row["id"],row["name"]);
  7. }
  8. mysql_free_result($result);
复制代码

35、gd库是做什么用的? (1分) 动态的开放的图片处理库 36、指出一些在php输入一段html代码的办法。(1分)

  1. echo "{html}"
  2. echo {html}
  3. eod;
复制代码

37、下面哪个函数可以打开一个文件,以对文件进行读和写操作?(1分) c   (a) fget() (b) file_open() (c) fopen() (d) open_file() 38、下面哪个选项没有将 john 添加到users 数组中? (1分) b

  1.   (a) $users[] = ‘john’;
  2.   (b) array_add($users,’john’);
  3.   (c) array_push($users,‘john’);
  4.   (d) $users ||= ‘john’;
复制代码

39、下面的程序会输入是否?(1分) 10

  1. $num = 10;
  2.   function multiply(){
  3.   num=num * 10;
  4.   }
  5.   multiply();
  6.   echo $num;
复制代码

40、使用php写一段简单查询,查出所有姓名为“张三”的内容并打印出来 (2分) 表名 username tel content date  张三 13333663366 大专毕业 2006-10-11  张三 13612312331 本科毕业 2006-10-15  张四 021-55665566 中专毕业 2006-10-15 请根据上面的题目完成代码:

  1.   $mysql_db=mysql_connect("local","root","pass");
  2.   @mysql_select_db("db",$mysql_db);
  3. $sql = sprintf("select * from %s where username = '%s'",
  4. "表名",
  5. "张三");
  6. values=mysqlquery(sql);
  7. while(item=mysqlfetchqueryarray(values))
  8. {
  9. echo sprintf("用户名:%s, 电话 %s, 学历: %s, 毕业日期: %s",
  10. item[′username′],item['tel'], item[′content′],item['date']
  11. );
  12. }
复制代码

41、如何使用下面的类,并解释下面什么意思?(3)

  1. class test{
  2.   function get_test($num){
  3.   num=md5(md5(num)."en");
  4.   return $num;
  5.   }
  6. }
  7. $test = new test();
  8. ret=test->get_test(11);
  9. print_r($ret);exit;
复制代码

将num进行md5编码之后生成的32位字符串a1和"en"联系起来之后再进行一次md5编码 42、写出 sql语句的格式 : 插入 ,更新 ,删除 (4分) 表名 username tel content date  张三 13333663366 大专毕业 2006-10-11  张三 13612312331 本科毕业 2006-10-15  张四 021-55665566 中专毕业 2006-10-15   (a) 有一新记录(小王 13254748547 高中毕业 2007-05-06)请用sql语句新增至表中 insert into 表名 values('小王', '13254748547', '高中毕业', '2007-05-06')   (b) 请用sql语句把张三的时间更新成为当前系统时间 update 表名 set date = getdate() where username = "张三"   (c) 请写出删除名为张四的全部记录 delete from 表明 where username = "张四" 43、请写出数据类型(int char varchar datetime text)的意思; 请问varchar和char有什么区别(2分) int 整型 char 存储定长 varchar 存储变长 datetime 时间 text 存储变长的 varchar是变长 char(20) 定长 44、mysq自增类型(通常为表id字段)必需将其设为(?)字段(1分) auto_increment   45、写出以下程序的输出结果 (1分)   $b=201;   $c=40;   a=b>$c?4:5;   echo $a; ?> 4

46、检测一个变量是否有设置的函数是否?是否为空的函数是?(2分) isset() empty() 47、取得查询结果集总数的函数是?(1分) mysql_num_rows() 48、

  1. $arr = array('james', 'tom', 'symfony'); 请打印出第一个元素的值 (1分)
  2. print_r($arr[0]);
  3. reset($arr);
  4. print_r(current($arr));
  5. print_r(array_shift($arr)); (程序员之家 bbs.it-home.org 编辑整理)
复制代码

49、请将41题的数组的值用','号分隔并合并成字串输出(1分) implode 50、a=′abcdef′;请取出a的值并打印出第一个字母(1分) $a[0]; substr($a, 0, 1); 51、php可以和sql server/oracle等数据库连接吗?(1分) 可以 有现成的库 52、请写出php5权限控制修饰符(3分) public private protected 53、请写出php5的构造函数和析构函数(2分) public function __construct() { } public function __destruct() { } 编程题    1. 写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名 例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php

  1. $url = "http://www.sina.com.cn/abc/de/fg.php?id=1";
  2. arr=parseurl(url);
  3. patharr=pathinfo(arr['path']);
  4. print_r($patharr['extension']);
复制代码

3. 写一个函数,算出两个文件的相对路径 如 $a = '/a/b/c/d/e.php'; $b = '/a/b/12/34/c.php'; 计算出 b相对于a 的相对路径应该是 http://www.cnblogs.com/12/34/c.php将添上

  1. $a = '/a/b/c/d/e.php';
  2. $b = '/a/b/12/34/c.php';
  3. //获取path相对于conpath的相对路径
  4. function sgetrelativepath(path,conpath)
  5. {
  6. patharr=explode("/",path);
  7. conpatharr=explode("/",conpath);
  8. $dismatchlen = 0;
  9. for(i=0;i {
  10. if(conpatharr[i] != patharr[i])
  11. {
  12. dismatchlen=count(patharr) - $i;
  13. arrleft=arrayslice(patharr, $i);
  14. break;
  15. }
  16. }
  17. ret=strrepeat("../",dismatchlen).implode("/", $arrleft);
  18. return $ret;
  19. }
  20. print_r(sgetrelativepath(b,a));
复制代码

3.写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。

  1. function agetallfile($folder)
  2. {
  3. $afilearr = array();
  4. if(is_dir($folder))
  5. {
  6. handle=opendir(folder);
  7. while((file=readdir(handle)) !== false)
  8. {
  9. //如果是.或者..则跳过
  10. if(file=="."||file == "..")
  11. {
  12. continue;
  13. }
  14. if(is_file(folder."/".file))
  15. {
  16. afilearr[]=file;
  17. }
  18. else if(is_dir(folder."/".file))
  19. {
  20. afilearr[file] = agetallfile(folder."/".file);
  21. }
  22. }
  23. closedir($handle);
  24. }
  25. return $afilearr;
  26. }
  27. $path = "/home/test/sql";
  28. print_r(agetallfile($path));
复制代码


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!