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
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。