- 相關推薦
比較基礎的php面試題及答案-填空題
填空題:
1.在PHP中,當前腳本的名稱(不包括路徑和查詢字符串)記錄在預定義變量__$_SERVER['PHP_SELF']__中;而鏈接到當前頁面的URL記錄在預定義變量__$_SERVER['HTTP_REFERER']__
中
2.執行程序段將輸出__0__。
3.在HTTP 1.0中,狀態碼 401 的含義是____;如果返回“找不到文件”的提示,則可用 header 函數,其語句為____。
4.數組函數 arsort 的作用是__對數組進行逆向排序并保持索引關系__;語句 error_reporting(2047)的作用是__報告所有錯誤和警告__。
5.PEAR中的數據庫連接字符串格式是____。
6.寫出一個正則表達式,過慮網頁上的所有JS/VBS腳本(即把scrīpt標記及其內容都去掉):preg_replace(“//si”, “newinfo”, $script);
7.以Apache模塊的方式安裝PHP,在文件http.conf中首先要用語句____動態裝載PHP模塊,然后再用語句____使得Apache把所有擴展名為php的文件都作為PHP腳本處理。
LoadModule php5_module “c:/php/php5apache2.dll” , AddType application/x-httpd-php .php,
8.語句 include 和 require 都能把另外一個文件包含到當前文件中,它們的區別是____;為了避免多次包含同一文件,可以用語句__require_once||include_once__來代替它們。
9.類的屬性可以序列化后保存到 session 中,從而以后可以恢復整個類,這要用到的函數是____。
10.一個函數的參數不能是對變量的引用,除非在php.ini中把__allow_call_time_pass_reference boolean__設為on.
11.SQL中LEFT JOIN的含義是__自然左外鏈接__。如果 tbl_user記錄了學生的姓名(name)和學號(ID),tbl_score記錄了學生(有的學生考試以后被開除了,沒有其記錄)的學號(ID)
和考試成績(score)以及考試科目(subject),要想打印出各個學生姓名及對應的的各科總成績,則可以用SQL語句____。
12.在PHP中,heredoc是一種特殊的字符串,它的結束標志必須____。
編程題:
13.寫一個函數,能夠遍歷一個文件夾下的所有文件和子文件夾。
答:
function my_scandir($dir)
{
$files = array();
if ( $handle = opendir($dir) ) {
while ( ($file = readdir($handle)) !== false ) {
if ( $file != “..” && $file != “.” ) {
if ( is_dir($dir . “/” . $file) ) {
$files[$file] = scandir($dir . “/” . $file);
}else {
$files[] = $file;
}
}
}
closedir($handle);
return $files;
}
}
14.簡述論壇中無限分類的實現原理。
答:
/*
數據表結構如下:
CREATE TABLE `category` (
`categoryID` smallint(5) unsigned NOT NULL auto_increment,
`categoryParentID` smallint(5) unsigned NOT NULL default ’0′,
`categoryName` varchar(50) NOT NULL default ”,
PRIMARY KEY (`categoryID`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
INSERT INTO `category` ( `categoryParentID`, `categoryName`) VALUES
(0, ‘一級類別’),
(1, ‘二級類別’),
(1, ‘二級類別’),
(1, ‘二級類別’),
(2, ‘三級類別’),
(2, ’333332′),
(2, ’234234′),
(3, ‘aqqqqqd’),
(4, ‘哈哈’),
(5, ’66333666′);
*/
//指定分類id變量$category_id,然后返回該分類的所有子類
//$default_category為默認的選中的分類
function Get_Category($category_id = 0,$level = 0, $default_category = 0)
{
global $DB;
$sql = “SELECT * FROM category ORDER BY categoryID DESC”;
$result = $DB->query( $sql );
while ($rows = $DB->fetch_array($result))
{
$category_array[$rows[categoryParentID]][$rows[categoryID]] = array(‘id’ => $rows[categoryID], ‘parent’ => $rows[categoryParentID], ‘name’ => $rows
[categoryName]);
}
if (!isset($category_array[$category_id]))
{
return “”;
}
foreach($category_array[$category_id] AS $key => $category)
{
if ($category['id'] == $default_category)
{
echo “\n”;
}
else
{
echo “>” . $category['name'] . “\n”;
}
Get_Category($key, $level + 1, $default_category);
}
unset($category_array[$category_id]);
}
/*
函數返回的數組格式如下所示:
Array
(
[1] => Array ( [id] => 1 [name] => 一級類別 [level] => 0 [ParentID] => 0 )
[4] => Array ( [id] => 4 [name] => 二級類別 [level] => 1 [ParentID] => 1 )
[9] => Array ( [id] => 9 [name] => 哈哈 [level] => 2 [ParentID] => 4 )
[3] => Array ( [id] => 3 [name] => 二級類別 [level] => 1 [ParentID] => 1 )
[8] => Array ( [id] => 8 [name] => aqqqqqd [level] => 2 [ParentID] => 3 )
[2] => Array ( [id] => 2 [name] => 二級類別 [level] => 1 [ParentID] => 1 )
[7] => Array ( [id] => 7 [name] => 234234 [level] => 2 [ParentID] => 2 )
[6] => Array ( [id] => 6 [name] => 333332 [level] => 2 [ParentID] => 2 )
[5] => Array ( [id] => 5 [name] => 三級類別 [level] => 2 [ParentID] => 2 )
[10] => Array ( [id] => 10 [name] => 66333666 [level] => 3 [ParentID] => 5 )
)
*/
//指定分類id,然后返回數組
function Category_array($category_id = 0,$level=0)
{
global $DB;
$sql = “SELECT * FROM category ORDER BY categoryID DESC”;
$result = $DB->query($sql);
while ($rows = $DB->fetch_array($result))
{
$category_array[$rows['categoryParentID']][$rows['categoryID']] = $rows;
}
foreach ($category_array AS $key=>$val)
{
if ($key == $category_id)
{
foreach ($val AS $k=> $v)
{
$options[$k] =
array(
‘id’ => $v['categoryID'], ‘name’ => $v['categoryName'], ‘level’ => $level, ‘ParentID’=>$v['categoryParentID']
);
$children = Category_array($k, $level+1);
if (count($children) > 0)
{
$options = $options + $children;
}
}
}
}
unset($category_array[$category_id]);
return $options;
}
?>
class cate
{
function Get_Category($category_id = 0,$level = 0, $default_category = 0)
{
echo $category_id;
$arr = array(
’0′ => array(
’1′ => array(‘id’ => 1, ‘parent’ => 0, ‘name’ => ’1111′),
’2′ => array(‘id’ => 2, ‘parent’ => 0, ‘name’ => ’2222′),
’4′ => array(‘id’ => 4, ‘parent’ => 0, ‘name’ => ’4444′)
),
’1′ => array(
’3′ => array(‘id’ => 3, ‘parent’ => 1, ‘name’ => ’333333′),
’5′ => array(‘id’ => 5, ‘parent’ => 1, ‘name’ => ’555555′)
),
’3′ => array(
’6′ => array(‘id’ => 6, ‘parent’ => 3, ‘name’ => ’66666′),
’7′ => array(‘id’ => 7, ‘parent’ => 3, ‘name’ => ’77777′)
),
’4′ => array(
’8′ => array(‘id’ => 8, ‘parent’ => 4, ‘name’ => ’8888′),
’9′ => array(‘id’ => 9, ‘parent’ => 4, ‘name’ => ’9999′)
)
);
if (!isset($arr[$category_id]))
{
return “”;
}
foreach($arr[$category_id] AS $key => $cate)
{
if ($cate['id'] == $default_category)
{
$txt = “\n”;
}else{
$txt1 = “>” . $cate['name'] . “\n”;
}
$val = $txt.$txt1;
echo $val;
self::Get_Category($key, $level + 1, $default_category);
}
}
function getFlush($category_id = 0,$level = 0, $default_category = 0)
{
ob_start();
self::Get_Category($category_id ,$level, $default_category);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
}
$id =$_GET['id'];
echo “”;
?>
【比較基礎的php面試題及答案-填空題】相關文章:
模擬電子技術基礎填空題及答案03-29
騰訊php程序員面試題目及答案08-03
計算機應用基礎試題及答案「填空題」11-30
PHP基礎筆試題12-10
PHP的基礎編程與應用04-01
關于PHP面試題的分享11-20
PHP筆試題及答案02-11
華為工程師通信基礎面試題及答案11-06
PHP入門基礎教程大全03-10
PHP筆試題含答案02-11