日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

基础面试1

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

M:代表自己的見解。? ?I:代表網絡查詢結果,答案


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

?

M:__FILE__是系統中魔術常量中的一種,記錄了當前文件夾的絕對路徑

?

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

?

?

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

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

I:$_SERVER[‘REMOTE_ADDR’]

?

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

?

?

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

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

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

?

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

M:.......

I:

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

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

? ? ??

?

?

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

M: 使用array_filter去除數組中的空值? ? ?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、寫出獲取當前時間戳的函數,及打印前一天的時間的方法(格式:年-月-日 時:分:秒) (5
分)

?

M: 獲取當前時間戳 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進行編碼轉換的函數(5分)

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

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

?

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

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

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

?

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

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

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

?

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

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

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,寫出獲得該文件擴展名的方法(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、請簡單寫一個類,實例化這個類,并寫出調用該類的屬性和方法的語句(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數據庫db_test里已建有表friend,數據庫的連接用戶為root,密碼為123

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

? ? ? ?連接數據庫

?

I:

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

?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)使用聯合查詢獲取name為“張三”的用戶的總分數(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為“李四”的用戶,包括分數記錄(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;

?

轉載于:https://www.cnblogs.com/yangtaog/p/11175360.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。