PHP公司面试题集锦

【公司面试题之:eruiyi.cn PHP笔试题】

 

1. 禁用COOKIE 后 SEESION 还能用吗?

2. 抓取远程图片到本地,你会用什么函数?

3. 已知姓名A,姓名B,给一个求他们缘份的算法

4. 你觉得在PV10W的时候, 同等配置下,LUNIX 比WIN快多少?

5. 简述POST 和GET传输的最大容量分别是多少?

6. 用最少的代码写一个求3值最大值的函数.

 

【公司面试题之:百度Web开发工程师笔试题】

百度笔试题(web开发和新产品搜索方向) 

第一部分:

1.解释下面语句的意思:document.form["formName"].submit;

 

2.有下面语句:

<input id="txt" type="text" value="baidu" />

编写代码,当鼠标划过文本框,自动选中文本框中的内容。

 

3.将字符09转换成十进制数字。

 

4.将1234567890转换成1,234,567,890 每3位用逗号隔开的形式。

$str = '1234567890';

function str($str){

$str = strrev($str);

$str = chunk_split($str,3, ',');

$str = strrev($str);

$str = ltrim($str, ',');

var_dump($str);

 

}

 

str($str);

 

5.关于HTML和CSS的,忘记了。

 

6.在文本框中输入一个年份,判断其生肖,并输出在文本框旁边。

对html和javaServlet都要求写出。

 

7.Ajax从服务器取数据 {id:123, name:"baidu", username:"mm",checked:true};

分析name对应的值("baidu").(题目较长,不记得了)

 

8.谈关于客户体验的问题。 

 

 

第二部分:

 

1.Ajax,数据库触发器,GUI,中断机制的共同思想。谈一谈该种思想(机制)。

 

2.把一篇英文文档中所有单词的首字母转为大写,文档存在doc.txt中。可以在多种编程语言中选择(C\C++,JAVA,PHP...)写出你的思路,尽量优化你的程序。

 

3.关于树的数据结构.

 

4.数据库优化:

有一个表 PRODUCT(ID,NAME,PRICE,COUNT);

在执行一下查询的时候速度总是很慢:

SELECT * FROM PRODUCT WHERE PRICE=100;

在price字段上加上一个非聚簇索引,查询速度还是很慢。

   (1)分析查询慢的原因。

   (2)如何进行优化。

 

5.CREATE TABLE topid{

topicId int not null primary key auto_increment,

title text,

author varchar(30),

content blob,

isDeleted int

......   //好像在author上定义了一个索引

}

CREATE TABLE reply{

topicId int foreign key,

replyId int primary key auto_increment,

replyAuthor varchar(30),

replyTime datetime,

context blob

....... //定义了一个索引和key

}

一个为主题表,一个为回复表。

 

1.问从性能上考虑,这样做有什么不足。

2.查询回复时间不超过一个特定的时间段,回复的作者名字以MIKE开头的主题

   的title,以如下的查询:

   select * from topic where replyid in (select replyid from reply where

   replyAuthor like 'mike%' and (currentTime()-replyTime<specialTime))

   从性能上考虑上述的查询语句有什么不足?

   如何进行优化?

 

 

【公司面试题之:Yahoo! PHP 笔试题】

1. Which of the following will not add john to the users array?

  1). $users[] = 'john';

  2). array_add($users,'john');

  3). array_push($users,'john');

  4). $users ||= 'john';

 

2. What's the difference between sort(), asort() and ksort? Under what circumstances would you use each of these?

 

3. What would the following code print to the browser? Why?

     $num = 10;

     function multiply(){

          $num = $num * 10;

     }

     multiply();

     echo $num;

 

4. What is the difference between a reference and a regular variable? How do you pass by reference & why would you want to?

 

5. What functions can you use to add library code to the currently running script?

 

6. What is the difference between foo() & @foo()?

 

7. How do you debug a PHP application?

 

8. What does === do? What's an example of something that will give true for '==', but not '==='?

 

9. How would you declare a class named myclass with no methods or properties?

 

10. How would you create an object, which is an instance of myclass?

 

11. How do you access and set properties of a class from within the class?

 

12. What is the difference between include & include_once? include & require?

 

13. What function would you use to redirect the browser to a new page?

     1). redir()

     2). header()

     3). location()

     4). redirect()

 

14. What function can you use to open a file for reading and writing?

     1). fget();

     2). file_open();

     3). fopen();

     4). open_file();15. What's the difference between mysql_fetch_row() and mysql_fetch_array()?

 

16. What does the following code do? Explain what's going on there.

     $date='08/26/2003';

     print ereg_replace(([0-9]+)/([0-9]+)/([0-9]+),2/1/3,$date);

 

17. Given a line of text $string, how would you write a regular expression to strip all the HTML tags from it?

 

18. What's the difference between the way PHP and Perl distinguish between arrays and hashes?

 

19. How can you get round the stateless nature of HTTP using PHP?

 

20. What does the GD library do?

 

21. Name a few ways to output (print) a block of HTML code in PHP?

 

22. Is PHP better than Perl? – Discuss.

 

这里有参考答案:http://d.download.csdn.net/down/505057/AnsonYe

 

 

【公司面试题之:酷讯PHP工程师笔试题】

PHP&HTML 基础操作题

● 有三个php文件位于同一目录下,内容为

a.php:-------

<?php function fa() { echo "in Function A\n"; }?>

b.php:-------

<?php include 'a.php'; ?>

<?php function fb() { fa(); echo "in Function B\n"; } ?>

c.php:-------

<?php include 'a.php'; ?>

<?php include 'b.php'; ?>

<?php fa(); fb(); ?>

使用浏览器访问 c.php,请问是否存在问题。

如果存在问题,请指出修正方法并写出浏览器查看效果

如果不存在问题,请写出浏览器查看效果

 

● 从表login中选出name字段包含admin的前10条结果所有信息的sql语句

● 准确的指出以下代码的显示结果

<table border=1 width=500 style="text-align:center;">

  <tr>

    <td rowspan=2 width=50% height=50>a</td>

    <td width=50% eight=25>d</td>

  </tr>

  <tr><td width=50% height=25>b</td></tr>

  <tr height=25><td colspan=2>c</td></tr>

</table>

 

● 准确的指出以下代码的显示结果

<style>

.a {

  position:relative; 

  height:200px;

  width:500px;

  border:solid 1px #000; 

  background:#FFF;

}

#b,#c {position:absolute; width:250px; height:90px;}

#b {top:30px;left:50px; background:#FF0000; z-index:1;}

#c {bottom:30px; right:50px; background:#0000FF;}

</style>

<div class="a">

  <div id="b"></div>

  <div id="c"></div>

</div>

 

● 请说明HTML文档中DTD的意义和作用

● 判断以下代码是否正确,如果有错,请指出错误,如果正确,请指出运行结果

var arr = new Array(new Array(1,2,3,4),

  new Array('abc', "def", "xyz"),

);

for(i = 0; i < arr.length; i++) {

  document.write(arr[0])

}

 

● 如何使用javascript获取当前DOM元素(obj)的左上角在整个文档中的位置

● 可以使用哪些方法使用javascript向服务器发出请求且不离开当前页面,简单对比各自的特点(如果存在)

●        请写出php连mysql连接中,获取下一个自增长id值的方法,可以写多个。

●        请问cgi和fastcgi有什么不同,你在什么情况下会选择哪个

●        Php中如何判断一个字符串是否是合法的日期模式:2007-03-13 13:13:13 。要求代码不超过5行。

●        Php中,如何获得一个数组的键值?

●        zend optimizer是什么

●         如何用命令把mysql里的数据备份出来

 

Linux操作:

● vi编辑器中,选中、复制、粘贴、删除的命令各是什么

● 获取文件行数

● 输入文件的最后5行到另一个文件中

● 查找文件中包含hello的行

●        查找当前目录下所有目录名为CVS的子目录的命令

●        删除当前目录下所有目录名为CVS的子目录的命令

●        如何让一个程序在后台运行并把输入定向到指定的文件

●        如何把一个文件的内容添加到另一个文件的末尾

●        如何实时的显示一个文件的输出

●        定时执行一个程序的方法有什么

●        Vi编辑器中,如何替换指定的字符串

●        当更新后,cvs中文件有冲突时。如何判断哪些你编辑的内容和更新下来的内容

 

【公司面试题之:腾讯PHP工程师笔试题】

1. 请对POSIX风格和兼容Perl风格两种正则表达式的主要函数进行类比说明 

ereg preg_match 

ereg_replace preg_replace 

 

2. 请说明在php.ini中safe_mode开启之后对于PHP系统函数的影响 

 

3. PHP5中魔术方法函数有哪几个,请举例说明各自的用法 

__sleep 

__wakeup 

__toString 

__set_state 

__construct, 

__destruct 

__call, 

__get, 

__set, 

__isset, 

__unset 

__clone 

__autoload 

 

4. 请写出让,并说明如何在命令行下运行PHP脚本(写出两种方式)同时向PHP脚本传递参数? 

 

5. PHP的垃圾收集机制是怎样的 

 

6.使对象可以像数组一样进行foreach循环,要求属性必须是私有。 

(Iterator模式的PHP5实现,写一类实现Iterator接口) 

 

7.请写一段PHP代码,确保多个进程同时写入同一个文件成功 

 

8. 用PHP实现一个双向队列 

 

9. 使用正则表达式提取一段标识语言(html或xml)代码段中指定标签的指定属性值(需考虑属性值对不规则的情况,如大小写不敏感,属性名值与等号间有空格等)。此处假设需提取test标签的attr属性值,请自行构建包含该标签的串 

<test attr=ddd> 

<test attr\s*=\s*[ &brvbar;’](.*?)[ &brvbar;’].*?> 

 

10.请使用socket相关函数(非curl)实现如下功能:构造一个post请求,发送到指定http server的指定端口的指定请求路径(如http://www.example.com:8080/test)。请求中包含以下变量: 

用户名(username):温柔一刀 

密码(pwd):&123=321&321=123& 

个人简介(intro):Hello world! 

且该http server需要以下cookie来进行简单的用户动作跟踪: 

cur_query:you&me 

last_tm:...(上次请求的unix时间戳,定为当前请求时间前10分钟) 

cur_tm:...(当前请求的unix时间戳) 

设置超时为10秒,发出请求后,将http server的响应内容输出。复制内容到剪贴板代码:

Function encode($data, $sep = ‘&’){ 

while (list($k,$v) = each($data)) { 

$encoded .= ($encoded ? "$sep" : ""); 

$encoded .= rawurlencode($k)."=".rawurlencode($v); 

Return $encoded; 

Function post($url, $post, $cookie){ 

$url = parse_url($url); 

$post = encode($data, ‘&’); 

$cookie = encode($cookieArray, ‘;’); 

$fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, 10); 

if (!$fp) return "Failed to open socket to $url[host]"; 

fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query'])); 

fputs($fp, "Host: $url[host]\n"); 

fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); 

fputs($fp, "Content-length: " . strlen($encoded) . "\n"); 

fputs($fp, "Cookie: $cookie\n\n"); 

fputs($fp, "Connection: close\n\n"); 

fputs($fp, "$post \n"); 

while (!feof($fp)) { 

echo fgets($fp, 128); 

fclose($fp); 

$url = ‘http://www.example.com:8080/test’; 

$encoded = username=温柔一刀& pwd= 

$post = array( 

‘username’=> ‘温柔一刀’, 

‘pwd => ‘&123=321&321=123&’, 

‘intro => ‘Hello world!’ 

); 

$cookie = array( 

‘cur_query’ => ‘you&me, 

‘last_tm’ => time() - 600, 

‘cur_tm ‘=> time() 

); 

Post($url, $post, $cookie); 11.你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在? 

1.脚本执行时间,启用xdebug,使用WinCacheGrind分析。 

2.数据库查询,mysql使用EXPLAIN分析查询,启用slow query log记录慢查询。 

 

PHP LAMP Engineer Test Paper 

Question 1 

What does <? echo count ("123") ?> print out? 

A) 3 

B) False 

C) Null 

D) 1 

E) 0 

Question 2 

Which of the following snippets prints a representation of 42 with two decimal places? 

A) printf("%.2d\n", 42); 

B) printf("%1.2f\n", 42); 

C) printf("%1.2u\n", 42); 

Question 3 

Given 

$text = 'Content-Type: text/xml'; 

Which of the following prints 'text/xml'? 

A) print substr($text, strchr($text, ':')); 

B) print substr($text, strchr($text, ':') + 1); 

C) print substr($text, strpos($text, ':') + 1); 

D) print substr($text, strpos($text, ':') + 2); 

E) print substr($text, 0, strchr($text, ':') 

Question 4 

What is the value of $a? 

<?php 

$a = in_array('01', array('1')) == var_dump('01' == 1); 

?> 

A) True 

B) False 

Question 5 

What is the value of $result in the following PHP code? 

<?php 

function timesTwo($int) { 

$int = $int * 2; 

$int = 2; 

$result = timesTwo($int); 

?>; 

Answer: NULL 

Question 6 

The code below ___________ because ____________. 

<?php 

class Foo { 

?> 

<?php 

function bar() { 

print "bar"; 

?> 

A) will work, class definitions can be split up into multiple PHP blocks. 

B) will not work, class definitions must be in a single PHP block. 

C) will not work, class definitions must be in a single file but can be in multiple PHP blocks. 

D) will work, class definitions can be split up into multiple files and multiple PHP blocks. 

Question 7 

When turned on, ____________ will _________ your script with different variables from HTML forms and cookies. 

A) show_errors, enable 

B) show_errors, show 

C) register_globals, enhance 

D) register_globals, inject 

Question 8 

What will be the output of the following PHP code: 

<?php 

echo count(strlen("http://php.net")); 

?> 

Answer: 1 

Question 9 

What is the best all-purpose way of comparing two strings? 

A) Using the strpos function 

B) Using the == operator 

C) Using strcasecmp() 

D) Using strcmp() 

Question 10 

What is the difference between "print()" and "echo()"? 

Answer: print is a function,echo is a language construct

 

 

【公司面试题之:新浪PHP工程师笔试题】

1. 写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名

  例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php 

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

  <META http-equiv='Content-Type' content='text/html; charset=gbk'>

  请使用 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将()添上

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

5.简述论坛中无限分类的实现原理。

6.设计一个网页,使得打开它时弹出一个全屏的窗口,该窗口中有一个文本框和一个按钮。用户在文本框中输入信息后点击按钮就可以把窗口关闭,而输入的信息却在主网页中显示。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

热门产品

历史上的今天:03月28日

热门专题

云南综合高中|云南综合高中
云南综合高中
安徽中源管业有限公司|安徽中源管业有限公司,安徽中源管业有限公司介绍,安徽中源管业有限公司电话,安徽中源管业有限公司地址,安徽中源管业有限公司厂家,安徽中源管业有限公司电力管,安徽中源管业有限公司管材
安徽中源管业有限公司
综合高中|云南综合高中,昆明综合高中,综合高中能考本一吗,综合高中和普通高中的区别,综合高中是什么意思,综合高中能参加全国统一高考吗,综合高中可以考哪些大学,综合高中的学籍是什么
综合高中
大理科技管理学校|大理科技管理学校,大理科技,大理科技中等职业技术学校,大理科技管理中等职业技术学校,大理科技学校
大理科技管理学校
易捷尔单招|易捷尔单招,易捷尔单招培训,易捷尔单招报名,易捷尔单招考试,易捷尔单招培训学校,易捷尔单招分数
易捷尔单招
云南开放大学|云南开放大学报名,云南开放大学报考,云南开放大学,什么是云南开放大学,云南开放大学学历,云南开放大学学费,云南开放大学报名条件,云南开放大学报名时间,云南开放大学学历,云南开放大学专业
云南开放大学
云南巨榕教育投资集团有限公司|云南巨榕教育投资集团有限公司,巨榕教育集团,巨榕教育
云南巨榕教育投资集团有限公司
一年制中专|中专学历,中专是什么学历,中专是什么,中专有什么专业,中专升大专,一年制中专
一年制中专

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部