最全最詳細的PHP面試題(帶有答案)

來源:互聯網
上載者:User

標籤:目前時間   name   __file__   fun   串連失敗   get   文字檔   一段   header函數   

這篇文章介紹的內容是關於最全最詳細的PHP面試題(帶有答案),有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

 

1、__FILE__表示什麼意思?(5分)
檔案的完整路徑和檔案名稱。如果用在包含檔案中,則返回包含檔案名稱。自 PHP 4.0.2 起,__FILE__ 總是包含一個絕對路徑,而在此之前的版本有時會包含一個相對路徑。
2、如何擷取用戶端的IP地址?(5分)

1 $_SERVER[‘REMOTE_ADDR’]

3、寫出使用header函數跳轉頁面的語句(5分)

1 Header(‘location:index.php’);

4、$str是一段html文本,使用Regex去除其中的所有js指令碼(5分)

12 $pattern = ‘/<script.*>\.+<\/script>/’;Preg_replace($pattern,’’,$str);

5、寫出將一個數組裡的空值去掉的語句(5分)

1 $arr = array(‘’,1,2,3,’’,19);

第一種方法:

123456 $array1 = array(‘  ‘,1,‘‘,2,3);print_r(array_filter($array1, "del"));function del($var){       return(trim($var)); }

第二種方法:

123 $arr=array("",1,2,3,"");$ptn="/\S+/i";print_r(preg_grep($ptn,$arr));

6、寫出擷取目前時間戳的函數,及列印前一天的時間的方法(格式:年-月-日 時:分:秒) (5分)

12 Time();Date(“Y-m-d H:i:s”,Strtotime(“-1 day”));

7、寫出php進行編碼轉換的函數(5分)

1 Iconv(‘utf-8’,’gb2312’,$str);

8、$str = “1,3,5,7,9,10,20”,使用什麼函數可以把字串str轉化為包含各個數位數組?(5分)

1 $arr = explode(“,”,$str);

9、serialize() /unserialize()函數的作用(5分)
serialize()和unserialize()在php手冊上的解釋是:
serialize — 產生一個可儲存的值的表示,傳回值為字串,此字串包含了表示 value 的位元組流,不丟失其類型和結構,可以儲存於任何地方。
unserialize — 從已儲存的表示中建立 PHP 的值
具體用法:

12 $arr = array(“測試1″,”測試2″,”測試3″);//數組$sarr = serialize($arr);//產生一個可儲存的值(用於儲存)

//用任意方法(例如:你要是吧$sarr存在一個文字檔中你就可以用file_get_contents取得)得到儲存的值儲存在$newarr中;

1 $unsarr=unserialize($newarr);//從已儲存的表示中建立 PHP 的值

10、寫出一個函數,參數為年份和月份,輸出結果為指定月的天數(5分)

123 Function day_count($year,$month){Echo date(“t”,strtotime($year.”-”.$month.”-1”));}

11、一個檔案的路徑為/wwwroot/include/page.class.php,寫出獲得該副檔名的方法(5分)

12 $arr = pathinfo(“/wwwroot/include/page.class.php”);$str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));

12、你使用過哪種PHP的模板引擎?(5分)
Smarty,thinkphp內建的模板引擎
13、請簡單寫一個類,執行個體化這個類,並寫出調用該類的屬性和方法的語句(5分)

12345678910 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分)

12345678910 <?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;

 

 

 

http://www.php.cn/php-weizijiaocheng-393700.html

最全最詳細的PHP面試題(帶有答案)

相關文章

聯繫我們

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