PHP幾個比較常見的口試程式題整理

來源:互聯網
上載者:User
PHP幾個比較常見的面試程式題整理

反轉字串可以使用【strrev】但是最終要的就是多位元組字串

//反轉字串function mb_strrev($str){$len = mb_strlen($str,'utf-8');$r = array();for($i=0;$i<$len;$i++){$r[] = mb_substr($str,$i,1,'utf-8');}return implode(array_reverse($r));}

得到URL中副檔名,注意URL中不一定有副檔名的

//得到url中副檔名function getUrlExt($str){$url_info = parse_url($str);if(array_key_exists('path',$url_info)){$path = $url_info['path'];$file_info = pathinfo($path);if(array_key_exists('extension',$file_info)){return $file_info['extension'];}}return false;}


計算兩個檔案的相對路徑

function getrpath($path,$conpath){$pathArr = explode('/',$path);$conpathArr = explode('/',$conpath);//$dis_match_len = 0;for($i=0;$i

計算兩個檔案相對路徑的方法2,使用PHP內建函數【array_diff_assoc】

function getrpath2($path,$conpath){$pathA = explode('/',$path);$pathB = explode('/',$conpath);$res = array_diff_assoc($pathA,$pathB);$path = '';for($i=0;$i

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.