某大公司的PHP面试题
管理提醒: 本帖被 haowubai 执行取消置顶操作()
1. 如何用php的环境变量得到一个网页地址的内容?ip地址又要怎样得到?
[php]
echo $_SERVER ['PHP_SELF'];
echo $_SERVER ['SERVER_ADDR'];
[/php]
2. 求两个日期的差数,例如2007-2-5 ~ 2007-3-6 的日期差数
[php]
$begin=strtotime('2007-2-5');
$end=strtotime('2007-3-6');
echo ($end-$begin)/(24*3600);
[/php]
3. 请写一个函数,实现以下功能:
字符串“open_door” 转换成 “OpenDoor”php校园招聘面试题库及答案、”make_by_id” 转换成 ”MakeById”。
[php]
function changeStyle(& $str) {
/*$str = str_replace ( _, , $str );
$str = ucwords ( $str );
$str = str_replace ( , , $str );
return $str;*/
$arrStr=explode('_',$str);
foreach($arrStr as $key=>$value){
$arrStr[$key]=strtoupper(substr($value,0,1)).substr($value,1);
}
return implode('',$arrStr);
}
$s = open_door;
echo changeStyle ( $s );
[/php]
4. 要求写一段程序,实现以下数组$arr1转换成数组$arr2:
[php]$arr1 = array (
'0' => array ('fid' => 1, 'tid' => 1, 'name' =>'Name1' ),
'1' => array ('fid' => 1, 'tid' => 2 , 'name' =>'Name2' ),
'2' => array ('fid' => 1, 'tid' => 5 , 'name' =>'Name3' ),
'3' => array ('fid' => 1, 'tid' => 7 , 'name' =>'Name4' ),
'4' => array ('fid' => 3, 'tid' => 9, 'name' =>'Name5' )
);
$arr2 = array (
'0' => array (
'0' => array ( 'tid' => 1, 'name' => 'Name1'),
'1' => array ( 'tid' => 2, 'name' => 'Name2'),
'2' => array ( 'tid' => 5, 'name' => 'Name3'),
'3' => array ( 'tid' => 7, 'name' => 'Name4')
),
'1' => array (
'0' => array ( 'tid' => 9, 'name' => 'Name5' )
)
);