部分公司PHP面試題(供參考)____PHP

來源:互聯網
上載者:User
騰訊: 1. 請對POSIX風格和相容Perl風格兩種Regex的主要函數進行類比說明
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. 使用Regex提取一段標識語言(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中檔案有衝突時。如何判斷哪些你編輯的內容和更新下來的內容  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.