PHP基礎面試題 - 第八天

「PHP學習網」 公衆號會天天分享一些面試題,正在找工做的小夥伴們能夠來看看哦。

一、寫一個函數,儘量高效的,從一個標準 url 裏取出文件的擴展名例如: http://www.viphper.com/abc/12... 須要取出 php

答案:php

$url="http://www.viphper.com/abc/123/test.php?id=1&catid=15";
$str=parse_url($url);
echo end(explode(‘.’,$str[‘path’]))

二、將1234567890轉換成1,234,567,890 每3位用逗號隔開的形式。

答案:
Numbe_format() 要格式化的數字|規定多少個小數|規定用做小數點的字符串|規定用做千位分隔符的字符串
或者:面試

$str=」1234567890」;
function test($str){
    $foo=Strlen($str);
    $s=」」;
    $n=0;
    for($i=$foo-1;$i>=0,$i--){
        $s=$str[$i].$s;
        $n++;
        if($n>3){
    $s=」,」.$s;
    $n=1;
}
}
    return trim($s,」,」);
}

三、jQuery中,$('#main') 與 document.getElementById('main')是什麼樣的關係?

答案:二者都是獲取id爲main的對象函數

四、php文件中沒有結束標記'?>',有什麼好處?如:

<?php
  // @file demo.class.php
  class demo {
     function __construct() {

     }
  }
 // end 到此整個文件結束

答案:在包含文件時不會直接結束從而影響到程序的執行。學習

五、寫一個類實現接口ArrayAccess

Class me implements ArrayAccess{
  //重寫接口類中的方法
}
六、分別輸出(1)、(2)運行結果,試簡述過程。
class sample {
     function __call($a, $b){
         echo ucwords(implode(' ', $b).' '.$a);
     }
     function ads(){
         ob_start();
         echo 'by';
         return $this;
     }
     function ade(){
         $c = ob_get_clean();
        $this->php('power', $c);
     }
 }
 $inst = new sample();
 (1) $inst->viphper('welcome', 'to');
 (2) $inst->ads()->ade();

答案:
(1) Welcome To Viphper
(2) Power By Phpthis

關注公衆號,查看更多面試題

weixin.jpg

相關文章
相關標籤/搜索