這篇文章介紹的內容是關于最全最詳細的PHP面試題(帶有答案),有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
相關推薦:
分享一波騰訊PHP面試題
2019年PHP最新面試題(含答案)
Redis 高級面試題 學會這些還怕進不了大廠?
阿里面試官三年經驗PHP程式員知識點匯總,學會你就是下一個阿里人!
php面試題之PHP核心技術
掌握 Redis這些 知識點,面試官一定覺得你很 NB
1、__FILE__表示什么意思?(5分)
檔案的完整路徑和檔案名,如果用在包含檔案中,則回傳包含檔案名,自 PHP 4.0.2 起,__FILE__ 總是包含一個絕對路徑,而在此之前的版本有時會包含一個相對路徑,
2、如何獲取客戶端的IP地址?(5分)
$_SERVER[‘REMOTE_ADDR’]
3、寫出使用header函式跳轉頁面的陳述句(5分)
Header(‘location:index.php’);
4、$str是一段html文本,使用正則運算式去除其中的所有js腳本(5分)
$pattern = ‘/<script.*>\.+<\/script>/’;
Preg_replace($pattern,’’,$str);
5、寫出將一個陣列里的空值去掉的陳述句(5分)
$arr = array(‘’,1,2,3,’’,19);
第一種方法:
$array1 = array(' ',1,'',2,3);
print_r(array_filter($array1, "del"));
function del($var)
{
return(trim($var));
}
第二種方法:
$arr=array("",1,2,3,"");
$ptn="/\S+/i";
print_r(preg_grep($ptn,$arr));
6、寫出獲取當前時間戳的函式,及列印前一天的時間的方法(格式:年-月-日 時:分:秒) (5分)
Time();
Date(“Y-m-d H:i:s”,Strtotime(“-1 day”));
7、寫出php進行編碼轉換的函式(5分)
Iconv(‘utf-8’,’gb2312’,$str);
8、$str = “1,3,5,7,9,10,20”,使用什么函式可以把字串str轉化為包含各個數字的陣列?(5分)
$arr = explode(“,”,$str);
9、serialize() /unserialize()函式的作用(5分)
serialize()和unserialize()在php手冊上的解釋是:
serialize — 產生一個可存盤的值的表示,回傳值為字串,此字串包含了表示 value 的位元組流,不丟失其型別和結構,可以存盤于任何地方,
unserialize — 從已存盤的表示中創建 PHP 的值
具體用法:
$arr = array(“測驗1″,”測驗2″,”測驗3″);//陣列
$sarr = serialize($arr);//產生一個可存盤的值(用于存盤)
//用任意方法(例如:你要是吧$sarr存在一個文本檔案中你就可以用file_get_contents取得)得到存盤的值保存在$newarr中;
$unsarr=unserialize($newarr);//從已存盤的表示中創建 PHP 的值
10、寫出一個函式,引數為年份和月份,輸出結果為指定月的天數(5分)
Function day_count($year,$month){
Echo date(“t”,strtotime($year.”-”.$month.”-1”));
}
11、一個檔案的路徑為/wwwroot/include/page.class.php,寫出獲得該檔案擴展名的方法(5分)
$arr = pathinfo(“/wwwroot/include/page.class.php”);
$str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));
12、你使用過哪種PHP的模板引擎?(5分)
Smarty,thinkphp自帶的模板引擎
13、請簡單寫一個類,實體化這個類,并寫出呼叫該類的屬性和方法的陳述句(5分)
Class myclass{
Public $aaa;
Public $bbb;
Public function myfun(){
Echo “this is my function”;
}
}
$myclass = new myclass();
$myclass->$aaa;
$myclass->myfun();
14、本地mysql資料庫db_test里已建有表friend,資料庫的連接用戶為root,密碼為123
friend表欄位為:id,name,age,gender,phone,email
請使用php連接mysql,選擇出friend表里age > 20的所有記錄列印結果,并統計出查詢出的結果總數,(5分)
<?php
$link = Mysql_connect(“localhost”,”root”,”123”) or die(“資料庫連接失敗!”);
Mysql_select_db(“db_test”,$link) or die(“選擇資料庫失敗!”);
$sql = “select id,name,age,gender,phone,email from friend where age>20”;
$result = mysql_query($sql);
$count = mysql_num_rows($result);
While($row = mysql_fetch_assoc($result)){
Echo $row[‘id’];
….
}
15、以下有兩個表
user表 欄位id (int),name (varchar)
score表 欄位uid (int),subject (varchar) ,score (int)
score表的uid欄位與user表的id欄位關聯
要求寫出以下的sql陳述句
1)在user表里新插入一條記錄,在score表里插入與新加入的記錄關聯的兩條記錄(5分)
2)獲取score表里uid為2的用戶score最高的5條記錄(5分)
3)使用聯合查詢獲取name為“張三”的用戶的總分數(5分)
4)洗掉name為“李四”的用戶,包括分數記錄(5分)
5)清空score表(5分)
6)洗掉user表(5分)
1). mysql_query(“insert into user(name) values(‘test’)”);
$id = mysql_insert_id();
Mysql_query(“insert into score(uid,subjext,score) values(“.$id.”,’english’,’99’)”);
2).$sql = select uid,sunjext,score from score where uid=2 order by score desc limit 0,5;
3).select s.score from score s RIGHT JOIN user u ON u.id=s.uid where u.name=’張三;
4).delete from score where uid in(select id from user where name=’李四’);
Delete from user where name=’李四’;
5).delete from score;
6).drop table user;
以上就是最全最詳細的PHP面試題(帶有答案)的詳細內容
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/89891.html
標籤:PHP
上一篇:PHP四大主流框架的優缺點總結
