程序员找工作必备 PHP 基础面试题 - 第八天

309 阅读1分钟

“PHP学习网” 公众号会每天分享一些面试题,正在找工作的小伙伴们可以来看看哦。

1、写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名例如: 从链接abc.com/test.php需要取出 php

答案:

$url="http://www.viphper.com/abc/123/test.php?id=1&catid=15";
$str=parse_url($url);
echo end(explode(‘.’,$str[‘path’]))

2、将1234567890转换成1,234,567,890 每3位用逗号隔开的形式。

答案: Numbe_format() 要格式化的数字|规定多少个小数|规定用作小数点的字符串|规定用作千位分隔符的字符串 或者:

$str=”1234567890”;
function test($str){
	$foo=Strlen($str);
	$s=””;
	$n=0;
	for($i=$foo-1;$i>=0,$i--){
		$s=$str[$i].$s;
		$n++;
		if($n>3){
	$s=”,”.$s;
	$n=1;
}
}
	return trim($s,”,”);
}

3、jQuery中,$('#main') 与 document.getElementById('main')是什么样的关系?

答案:两者都是获取id为main的对象

4、php文件中没有结束标记'?>',有什么好处?如:

  <?php
  // @file demo.class.php
  class demo {
 	function __construct() {

 	}
  }
 // end 到此整个文件结束

答案:在包含文件时不会直接结束从而影响到程序的执行。

5、写一个类实现接口ArrayAccess

Class me implements ArrayAccess{
  //重写接口类中的方法
}
6、分别输出(1)、(2)运行结果,试简述过程。
 class sample {
 	function __call($a, $b){
 		echo ucwords(implode(' ', $b).' '.$a);
 	}
 	function ads(){
 		ob_start();
 		echo 'by';
 		return $this;
 	}
 	function ade(){
 		$c = ob_get_clean();
		$this->php('power', $c);
 	}
 }
 $inst = new sample();
 (1) $inst->viphper('welcome', 'to');
 (2) $inst->ads()->ade();

答案: (1) Welcome To Viphper (2) Power By Php

最后各位可以扫下方二维码关注我公众号,目前我正在更新基础面试题,之后会更新中高级、redis、liunx面试题