部分公司PHP面试题(供参考)

2023-10-25 12:08

本文主要是介绍部分公司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
__sleep,
__wakeup,
__toString,
__set_state,
__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*[“ ¦’](.*?)[” ¦’].*?>


10.请使用socket相关函数(非c url)实现如下功能:构造一个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 = ‘[url]http://www.example.com:8080/test[/url]’;
$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
Sina:
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.设计一个网页,使得打开它时弹出一个全屏的窗口,该窗口中有一个文本框和一个按钮。用户在文本框中输入信息后点击按钮就可以把窗口关闭,而输入的信息却在主网页中显示。
Yahoo:
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 “my class” 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.
Baidu:
第一部分:

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


2.有下面语句:
<input id="txt" type="text" value="baidu" />
编写代码,当鼠标划过文本框,自动选中文本框中的内容。


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


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


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))
   从性能上考虑上述的查询语句有什么不足?
   如何进行优化?
酷讯:
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面试题(供参考)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/282459

相关文章

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

荣耀嵌入式面试题及参考答案

在项目中是否有使用过实时操作系统? 在我参与的项目中,有使用过实时操作系统。实时操作系统(RTOS)在对时间要求严格的应用场景中具有重要作用。我曾参与的一个工业自动化控制项目就采用了实时操作系统。在这个项目中,需要对多个传感器的数据进行实时采集和处理,并根据采集到的数据及时控制执行机构的动作。实时操作系统能够提供确定性的响应时间,确保关键任务在规定的时间内完成。 使用实时操作系统的

一些其他面试题

阿里二面:那你来说说定时任务?单机、分布式、调度框架下的定时任务实现是怎么完成的?懵了。。_哔哩哔哩_bilibili 1.定时算法 累加,第二层每一个格子是第一层的总时间400 ms= 20 * 20ms 2.MQ消息丢失 阿里二面:高并发场景下引进消息队列有什么问题?如何保证消息只被消费一次?真是捏了一把汗。。_哔哩哔哩_bilibili 发送消息失败

zookeeper相关面试题

zk的数据同步原理?zk的集群会出现脑裂的问题吗?zk的watch机制实现原理?zk是如何保证一致性的?zk的快速选举leader原理?zk的典型应用场景zk中一个客户端修改了数据之后,其他客户端能够马上获取到最新的数据吗?zk对事物的支持? 1. zk的数据同步原理? zk的数据同步过程中,通过以下三个参数来选择对应的数据同步方式 peerLastZxid:Learner服务器(Follo

java常用面试题-基础知识分享

什么是Java? Java是一种高级编程语言,旨在提供跨平台的解决方案。它是一种面向对象的语言,具有简单、结构化、可移植、可靠、安全等特点。 Java的主要特点是什么? Java的主要特点包括: 简单性:Java的语法相对简单,易于学习和使用。面向对象:Java是一种完全面向对象的语言,支持封装、继承和多态。跨平台性:Java的程序可以在不同的操作系统上运行,称为"Write once,

笔记整理—内核!启动!—kernel部分(2)从汇编阶段到start_kernel

kernel起始与ENTRY(stext),和uboot一样,都是从汇编阶段开始的,因为对于kernel而言,还没进行栈的维护,所以无法使用c语言。_HEAD定义了后面代码属于段名为.head .text的段。         内核起始部分代码被解压代码调用,前面关于uboot的文章中有提到过(eg:zImage)。uboot启动是无条件的,只要代码的位置对,上电就工作,kern

创业者该如何设计公司的股权架构

本文来自七八点联合IT橘子和车库咖啡的一系列关于设计公司股权结构的讲座。 主讲人何德文: 在公司发展的不同阶段,创业者都会面临公司股权架构设计问题: 1.合伙人合伙创业第一天,就会面临股权架构设计问题(合伙人股权设计); 2.公司早期要引入天使资金,会面临股权架构设计问题(天使融资); 3.公司有三五十号人,要激励中层管理与重要技术人员和公司长期走下去,会面临股权架构设计问题(员工股权激

PHP原理之内存管理中难懂的几个点

PHP的内存管理, 分为俩大部分, 第一部分是PHP自身的内存管理, 这部分主要的内容就是引用计数, 写时复制, 等等面向应用的层面的管理. 而第二部分就是今天我要介绍的, zend_alloc中描写的关于PHP自身的内存管理, 包括它是如何管理可用内存, 如何分配内存等. 另外, 为什么要写这个呢, 因为之前并没有任何资料来介绍PHP内存管理中使用的策略, 数据结构, 或者算法. 而在我们

php中json_decode()和json_encode()

1.json_decode() json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0) json_decode — 对 JSON 格式的字符串进行编码 说明 mixed json_decode ( string $json [, bool $assoc ] ) 接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 参数 json

如何将文件夹里的PHP代码放到一个文件里

find ./dir -name "*.php" -exec 'cat' {} \; > dir.out