- PHP面試之編程題及答案 推薦度:
- 相關(guān)推薦
2017年P(guān)HP面試編程題
PHP是屬于后端的工程師,因此被問到編程問題是避免不了的,以下是百分網(wǎng)小編精心為大家整理的2017年P(guān)HP面試編程題,希望對(duì)大家有所幫助!更多內(nèi)容請(qǐng)關(guān)注應(yīng)屆畢業(yè)生網(wǎng)!
1. 寫一個(gè)函數(shù),盡可能高效的,從一個(gè)標(biāo)準(zhǔn) url 里取出文件的擴(kuò)展名
例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php
$url = "http://www.sina.com.cn/abc/de/fg.php?id=1";
arr=parseurl(arr=parseurl(url);
pathArr=pathinfo(pathArr=pathinfo(arr['path']);
print_r($pathArr['extension']);
3. 寫一個(gè)函數(shù),算出兩個(gè)文件的相對(duì)路徑
如 $a = '/a/b/c/d/e.php';
$b = '/a/b/12/34/c.php';
計(jì)算出 b相對(duì)于b相對(duì)于a 的相對(duì)路徑應(yīng)該是 http://www.cnblogs.com/12/34/c.php將添上
$a = '/a/b/c/d/e.php';
$b = '/a/b/12/34/c.php';
//獲取path相對(duì)于conpath的相對(duì)路徑
function sGetRelativePath(path,path,conpath)
{
pathArr=explode("/",pathArr=explode("/",path);
conpathArr=explode("/",conpathArr=explode("/",conpath);
$dismatchlen = 0;
for(i=0;i=0;i < count(pathArr);pathArr);i++)
{
if(conpathArr[conpathArr[i] != pathArr[pathArr[i])
{
dismatchlen=count(dismatchlen=count(pathArr) - $i;
arrLeft=arrayslice(arrLeft=arrayslice(pathArr, $i);
break;
}
}
ret=strrepeat("../",ret=strrepeat("../",dismatchlen).implode("/", $arrLeft);
return $ret;
}
print_r(sGetRelativePath(b,b,a));
3.寫一個(gè)函數(shù),能夠遍歷一個(gè)文件夾下的所有文件和子文件夾。
function aGetAllFile($folder)
{
$aFileArr = array();
if(is_dir($folder))
{
handle=opendir(handle=opendir(folder);
while((file=readdir(file=readdir(handle)) !== false)
{
//如果是.或者..則跳過
if(file=="."||file=="."||file == "..")
{
continue;
}
if(is_file(folder."/".folder."/".file))
{
aFileArr[]=aFileArr[]=file;
}
else if(is_dir(folder."/".folder."/".file))
{
aFileArr[aFileArr[file] = aGetAllFile(folder."/".folder."/".file);
}
}
closedir($handle);
}
return $aFileArr;
}
$path = "/home/test/sql";
print_r(aGetAllFile($path));
【PHP面試編程題】相關(guān)文章:
PHP編程面試題集10-06
PHP編程與應(yīng)用06-06
php語言編程07-06
PHP Socket編程過程07-19
學(xué)習(xí)PHP編程語言的優(yōu)勢(shì)08-09
如何自學(xué)PHP編程語言07-28
PHP編程語言搶手的原因08-11