1 請說明 PHP 中傳值與傳引用的區別。什么時候傳值什么時候傳引用?
~~~
答: 傳值只是把某一個變量的值傳給了另一個變量,而引用則說明兩者指向了同一個地方。
~~~
2 在PHP中error_reporting這個函數有什么作用?
~~~
答: The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script.
~~~
3 請用正則表達式(Regular Expression)寫一個函數驗證電子郵件的格式是否正確。
答:
~~~
<?php
if(isset($_POST['action']) && $_POST['action']=='submitted')
{
????$email=$_POST['email'];
????if(!preg_match("/^(?:w+.?)*w+@(?:w+.?)*w+$/",$email))
???? {
????????echo "電子郵件檢測失敗";
???? }
????else
???? {
????????echo "電子郵件檢測成功";
???? }
}
else
{
?>
<html>
<head><title>EMAIL檢測</title>
<script type="text/javascript">
????function checkEmail(sText)
???? {
????????var reg=/^(?:w+.?)*w+@(?:w+.?)*w+$/;
????????var email=document.getElementById(sText).value;
????????if(!reg.test(email))
???????? {
???????????? alert("電子郵件檢測失敗");
???????? }
????????else
???????? {
???????????? alert("電子郵件格式正確");
???????? }
???? }
</script>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
電子郵件:<input type="text" id="email" name="email" /><br />
<input type="hidden" name="action" value="submitted" />
<input type="button" name="button" value="客戶端檢測" onclick="checkEmail('email')" />
<input type="submit" name="submit" value="服務器端檢測" />
</form>
</body>
</html>
<?php
}
?>
~~~
4 簡述如何得到當前執行腳本路徑,包括所得到參數。
~~~
<?php
echo "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
//echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>
~~~
5 有一個一維數組,里面存儲整形數據,請寫一個函數,將他們按從大到小的順序排列。要求執行效率高。并說明如何改善執行效率。(該函數必須自己實現,不能使用php函數)
?
~~~
<?php
function BubbleSort(&$arr)
{
????$cnt=count($arr);
????$flag=1;
????for($i=0;$i<$cnt;$i++)
???? {
????????if($flag==0)
???????? {
????????????return;
???????? }
????????$flag=0;
????????for($j=0;$j<$cnt-$i-1;$j++)
???????? {
????????????if($arr[$j]>$arr[$j+1])
???????????? {
????????????????$tmp=$arr[$j];
????????????????$arr[$j]=$arr[$j+1];
????????????????$arr[$j+1]=$tmp;
????????????????$flag=1;
???????????? }
???????? }
???? }
}
$test=array(1,3,6,8,2,7);
BubbleSort($test);
var_dump($test);
?>
~~~
?
6 請舉例說明在你的開發過程中用什么方法來加快頁面的加載速度
~~~
答:要用到服務器資源時才打開,及時關閉服務器資源,數據庫添加索引,頁面可生成靜態,圖片等大文件單獨服務器。使用代碼優化工具啦
~~~