日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

基础面试1

發(fā)布時間:2025/4/16 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基础面试1 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

M:代表自己的見解。? ?I:代表網(wǎng)絡(luò)查詢結(jié)果,答案


1、__FILE__表示什么意思?(5分)

?

M:__FILE__是系統(tǒng)中魔術(shù)常量中的一種,記錄了當(dāng)前文件夾的絕對路徑

?

I:?文件的完整路徑和文件名。如果用在包含文件中,則返回包含文件名。自 PHP 4.0.2 起,__FILE__ 總是包含一個絕對路徑,而在此之前的版本有時會包含一個相對路徑。

?

?

2、如何獲取客戶端的IP地址?(5分)

M:通過$_SERVER超全局變量來獲取, $_SERVER['remote_addr'] 請求中客戶端的ip地址

I:$_SERVER[‘REMOTE_ADDR’]

?

超全局變量中的參數(shù)詳解?https://www.cnblogs.com/rendd/p/6182918.html

?

?

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

M: header("404 http/1.1 頁面丟失了");

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

?

4、$str是一段html文本,使用正則表達(dá)式去除其中的所有js腳本(5分)

M:.......

I:

$pattern = ‘/<script.*>\.+<\/script>/’;

Preg_replace($pattern,’’,$str);

? ? ??

?

?

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

M: 使用array_filter去除數(shù)組中的空值? ? ?array_filter($arr);?

?

I:?

第一種:$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、寫出獲取當(dāng)前時間戳的函數(shù),及打印前一天的時間的方法(格式:年-月-日 時:分:秒) (5
分)

?

M: 獲取當(dāng)前時間戳 time(),? ? ?strtotime('Y年m月d日 H時i分s',time()-60*60*24)

I:Time();

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

? ? ??

7、寫出php進(jìn)行編碼轉(zhuǎn)換的函數(shù)(5分)

M: iconv('urf8','gbk',$str);

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

?

8、$str = “1,3,5,7,9,10,20”,使用什么函數(shù)可以把字符串str轉(zhuǎn)化為包含各個數(shù)字的數(shù)組
?(5分)

?M: 轉(zhuǎn)化為數(shù)組并轉(zhuǎn)換為int類型? ?array_map('intval',implode(',',$str));

?I:$arr = explode(“,”,$str);

?

9、serialize() /unserialize()函數(shù)的作用(5分)

M: serialize 講一個對象序列化成一個字符串,方便存入數(shù)據(jù)庫或其他地方,unserialize 將序列化后的字符串進(jìn)行反序列化成一個對象??

I:serialize()和unserialize()在php手冊上的解釋是:
serialize — 產(chǎn)生一個可存儲的值的表示,返回值為字符串,此字符串包含了表示 value 的字節(jié)流,不丟失其類型和結(jié)構(gòu),可以存儲于任何地方。
unserialize — 從已存儲的表示中創(chuàng)建 PHP 的值?

?

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

?M: 輸入年份,和月份返回制定月的天數(shù),只判斷了閏年的情況下??

public function getSumDay($year,$month)
{
$num = $year%4;
switch ($month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
echo 31;
break;

case 2:
if($num===0){
echo 28;
}else{
echo 29;
}
break;

case 4:
case 6:
case 9:
case 11:
case 12:
echo 30;
break;
}
}


I:

Function day_count($year,$month){

Echo date(“t”,strtotime($year.”-”.$month.”-1”));

}

11、一個文件的路徑為/wwwroot/include/page.class.php,寫出獲得該文件擴(kuò)展名的方法(5
分)

M:

第一種:pathinfo('/wwwroot/include/page.class.php',PATHINFO_EXTENSION);

第二種: end(explode('.','/wwwroot/include/page.class.php'))或者array_pop(explode('.','/wwwroot/include/page.class.php'));

第三種:substr('/wwwroot/include/page.class.php',-3);

?

I:

$arr = pathinfo(“/wwwroot/include/page.class.php”);

$str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));

?

?

?

12、你使用過哪種PHP的模板引擎?(5分)

?M: smarty模板引擎

?

I:Smarty,thinkphp自帶的模板引擎

?

13、請簡單寫一個類,實例化這個類,并寫出調(diào)用該類的屬性和方法的語句(5分)

M:

? ? class Getman

? ? {

? ? ? ? ? public $name='楊濤';

? ? ? ? ? public $age=18;

? ? ? ? ? public $sex='男';

? ? ? ? ? public function getSex()

? ? ? ? ? {

? ? ? ? ? ? ? ? ?return $this->sex;

? ? ? ? ? }

? ? }

$object = new Getman();

//獲取性別屬性

$sex = $object->sex;

//通過方法獲取性別

$sex = $object->getSex();

unset($object);

?

I:

Class myclass{

Public $aaa;

Public $bbb;

Public function myfun(){

Echo “this is my function”;

}

}

$myclass = new myclass();

$myclass->$aaa;

$myclass->myfun();

?

14、本地mysql數(shù)據(jù)庫db_test里已建有表friend,數(shù)據(jù)庫的連接用戶為root,密碼為123

M:? $link = mysqli_connect('127.0.0.1','root','123','db_test');

? ? ? ?連接數(shù)據(jù)庫

?

I:

14、本地mysql數(shù)據(jù)庫db_test里已建有表friend,數(shù)據(jù)庫的連接用戶為root,密碼為123
friend表字段為:id,name,age,gender,phone,email
請使用php連接mysql,選擇出friend表里age > 20的所有記錄打印結(jié)果,并統(tǒng)計出查詢出的結(jié)果總數(shù)。(5分)

<?php

$link = Mysql_connect(“l(fā)ocalhost”,”root”,”123”) or die(“數(shù)據(jù)庫連接失敗!”);

Mysql_select_db(“db_test”,$link) or die(“選擇數(shù)據(jù)庫失敗!”);

$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字段關(guān)聯(lián)
要求寫出以下的sql語句
1)在user表里新插入一條記錄,在score表里插入與新加入的記錄關(guān)聯(lián)的兩條記錄(5分)

?M:? ? insert into user(id,name) values(1,'yang');

? ? ? insert into score(uid,subject,score) values(1,'思想品德',89),(1,'語文',90);

I:

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)獲取score表里uid為2的用戶score最高的5條記錄(5分)

M:? ? ? select * from score where uid=2 limit 5 order by score desc;

I:2).$sql = select uid,sunjext,score from score where uid=2 order by score desc limit 0,5;?

?

3)使用聯(lián)合查詢獲取name為“張三”的用戶的總分?jǐn)?shù)(5分)

M:? ? ?select sum(s.score) from score as s left join user as u on u.id = s.uid? where u.name='張三';

?I:3).select s.score from score s RIGHT JOIN user u ON u.id=s.uid where u.name=’張三;

?

?

4)刪除name為“李四”的用戶,包括分?jǐn)?shù)記錄(5分)

M:? ?delete user,score from user,score where user.id=score.uid and user.name='李四';?

I:

4).delete from score where uid in(select id from user where name=’李四’);

Delete from user where name=’李四’;

?

5)清空score表(5分)

M:? ?turncate score;

I:5).delete from score;

?


6)刪除user表(5分)

M:? ?drop table user;?

I:6).drop table user;

?

轉(zhuǎn)載于:https://www.cnblogs.com/yangtaog/p/11175360.html

總結(jié)

以上是生活随笔為你收集整理的基础面试1的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。