相關推薦:2019年PHP面試題大匯總(收藏)
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面試題八之innoDB和myisam的區別
以上就是最全最詳細的PHP面試題(帶有答案)的詳細內容,更多請關注 其它相關文章!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答