php语言 百分网手机站

PHP工程师面试题集(3)

时间:2020-10-08 18:29:17 php语言

2017年PHP工程师面试题集

  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=a=b>$c?4:5;

  echo $a;

  ?>

  4

  46、检测一个变量是否有设置的函数是否?是否为空的函数是?(2分)

  isset()

  empty()

  -----------------------------------------------------------------------------

  47、取得查询结果集总数的函数是?(1分)

  mysql_num_rows()

  48、$arr = array('james', 'tom', 'symfony'); 请打印出第一个元素的值 (1分)

  print_r($arr[0]);

  reset($arr);

  print_r(current($arr));

  print_r(array_shift($arr));

  49、请将41题的数组的值用','号分隔并合并成字串输出(1分)

  implode

  50、a=′abcdef′;请取出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

  $url = "http://www.sina.com.cn/abc/de/fg.php?id=1";

  arr=parseurl(arr=parseurl(url);

  pathArr=pathinfo(pathArr=pathinfo(arr['path']);

  print_r($pathArr['extension']);

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

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

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

  计算出 b相对于b相对于a 的相对路径应该是 http://www.cnblogs.com/12/34/c.php将添上

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

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

  //获取path相对于conpath的相对路径

  function sGetRelativePath(path,path,conpath)

  {

  pathArr=explode("/",pathArr=explode("/",path);

  conpathArr=explode("/",conpathArr=explode("/",conpath);

  $dismatchlen = 0;

  for(i=0;i=0;i < count(pathArr);pathArr);i++)

  {

  if(conpathArr[conpathArr[i] != pathArr[pathArr[i])

  {

  dismatchlen=count(dismatchlen=count(pathArr) - $i;

  arrLeft=arrayslice(arrLeft=arrayslice(pathArr, $i);

  break;

  }

  }

  ret=strrepeat("../",ret=strrepeat("../",dismatchlen).implode("/", $arrLeft);

  return $ret;

  }

  print_r(sGetRelativePath(b,b,a));

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

  function aGetAllFile($folder)

  {

  $aFileArr = array();

  if(is_dir($folder))

  {

  handle=opendir(handle=opendir(folder);

  while((file=readdir(file=readdir(handle)) !== false)

  {

  //如果是.或者..则跳过

  if(file=="."||file=="."||file == "..")

  {

  continue;

  }

  if(is_file(folder."/".folder."/".file))

  {

  aFileArr[]=aFileArr[]=file;

  }

  else if(is_dir(folder."/".folder."/".file))

  {

  aFileArr[aFileArr[file] = aGetAllFile(folder."/".folder."/".file);

  }

  }

  closedir($handle);

  }

  return $aFileArr;

  }

  $path = "/home/test/sql";

  print_r(aGetAllFile($path));

【2017年PHP工程师面试题集】相关文章:

1.PHP面试题集

2.PHP编程面试题集

3.PHP的面试题集

4.php应聘面试题

5.PHP经典面试题

6.PHP经典面试题集锦

7.PHP数组面试题「最新」

8.值得深思的PHP面试题

9.PHP语言常用的面试题