關於國內著名網際網路企業PHP筆試試題

來源:果殼範文吧 1W

國內著名網際網路企業pHp筆試題

關於國內著名網際網路企業PHP筆試試題

面對目前全球金融危機,國內動盪的網際網路環境,那冬天就要到來,大家也在積極的尋找一個過冬的窩,所以估計辭職跳槽的人很多,特別為大家分享一些各個著名公司的pHp筆試題,為大家求職就業打好堅實基礎,希望大家都安然度過這個網際網路的冬季!

【公司面試題之: pHp筆試題】 2008-10-7 上海公司pHp筆試題1. 禁用COOKIE 後 SEESION 還能用嗎? 2. 抓取遠端圖片到本地,你會用什麼函式?

3. 已知姓名A,姓名B,給一個求他們緣份的演算法

4. 你覺得在pV10W的時候, 同等配置下,LUNIX 比WIN快多少?

5. 簡述pOST 和GET傳輸的最大容量分別是多少?

6. 用最少的程式碼寫一個求3值最大值的函式.

附部分答案(不保證是正確的解)

1. 能

2 fsockopen

3 隨意

4 10倍?

5 1024B, 2MB

6 function($a,$b,$c){

return $a>$b? ($a>$c? $a : $c) : ($b>$c? $b : $c );

}

1. 禁用COOKIE 後 SEESION 還能用嗎?

不能(java的servlet會在位址列產生一個jsessionid,現在一些大叢集,有些就是session複製搞的)

2. 抓取遠端圖片到本地,你會用什麼函式?

socket & file

3. 已知姓名A,姓名B,給一個求他們緣份的演算法

瞎扯談,我壓根就不相信!

4. 你覺得在pV10W的時候, 同等配置下,LUNIX 比WIN快多少?

不做優化的情況下一樣

5. 簡述pOST 和GET傳輸的最大容量分別是多少?

pOST, 中的檔案中預設是2M,所以大於2M,GET沒門, TCp中是C++的DWord,所以,小於1024B

6. 用最少的程式碼寫一個求3值最大值的函式.

function max3($a,$b,$c){

return ($a>$b)?(($a>$c)? $a : $c): (($b>$c)? $b: $c);

}

【公司面試題之:騰訊pHp工程師筆試題】

1. 請對pOSIX風格和相容perl風格兩種正則表示式的主要函式進行類比說明

ereg preg_match

ereg_replace preg_replace

2. 請說明在中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屬性值,請自行構建包含該標籤的串

10.請使用socket相關函式(非curl)實現如下功能:構造一個post請求,傳送到指定http server的指定埠的指定請求路徑(如http://example: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).”=”rlencode($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.0n”, $url[path], $url[query] ? “?” : “”, $url[query]));

fputs($fp, “Host: $url[host]n”);

fputs($fp, “Content-type: application/x-www-form-urlencodedn”);

fputs($fp, “Content-length: ” . strlen($encoded) . “n”);

fputs($fp, “Cookie: $cookienn”);

fputs($fp, “Connection: closenn”);

fputs($fp, “$post n”);

while (!feof($fp)) {

echo fgets($fp, 128);

}

fclose($fp);

}

$url = ‘http://example: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 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(“%.2dn”, 42);

B) printf(“%1.2fn”, 42);

C) printf(“%1.2un”, 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?

$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?

function timesTwo($int) {

$int = $int * 2;

}

$int = 2;

$result = timesTwo($int);

?>;

Answer: NULL

Question 6

The code below ___________ because ____________.

class Foo {

?>

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:

echo count(strlen(“”));

?>

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 裡取出檔案的副檔名

例如: 需要取出 php 或

2. 在 HTML 語言中,頁面頭部的 meta 標記可以用來輸出檔案的編碼格式,以下是一個標準的 meta 語句

請使用 pHp 語言寫一個函式,把一個標準 HTML 頁面中的類似 meta 標記中的 charset 部分值改為 big5

請注意:

(1) 需要處理完整的 html 頁面,即不光此 meta 語句

(2) 忽略大小寫

(3) ‘和” 在此處是可以互換的

(4) ‘Content-Type’ 兩側的引號是可以忽略的,但 ‘text/html; charset=gbk’ 兩側的不行

(5) 注意處理多餘空格

3. 寫一個函式,算出兩個檔案的相對路徑

熱門標籤