转PHP 面试题两个

<?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));
?>


echo chunk_split(base64_encode(file_get_contents('base64.txt'))); 
return shuffle(range(1,$n)); 

你可能感兴趣的:(PHP)