<?php/*=============================================================================# FileName: base64.php# Desc: 六間房筆試題一:讀取一個檔案,將其Base64編碼,每76個字元加一個換行 # Author: HouYongZheng# Time: 2013-05-20 14:25=============================================================================*/header('Content-Type: text/html; charset=utf-8');$body=file_get_contents('base64.txt');$base_body=base64_encode($body);$count=1;for($i=0;$i<strlen($base_body);$i=$i+76){$index=($count-1)*76;@$all_str.='<p>'.substr($base_body,$index,76).'</p>';$count++;}echo $all_str;?>
<?php/*=============================================================================# FileName: array.php# Desc: 六間房筆試題二:寫一個函數,參數為$n,產生一個數組,其元素為1~$n,各元素位置隨機排列,不得重複# Author: HouYongZheng# Time: 2013-05-20 15:01=============================================================================*/function rand_array($n){$array=array();$rand_array=array();for($i=1;$i<=$n;$i++){array_push($array,$i);}//return $array;for($i=0;$i<=($n-1);$i++){$rand=array_rand($array,1);array_push($rand_array,$array[$rand]);unset($array[$rand]);}return $rand_array;}var_dump(rand_array(10));?>