PHP基础面试题 – 第八天

PHP基础题 2020年3月16日 3.03K

1、写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名例如: http://www.viphper.com/abc/123/test.php?id=1&catid=15 需要取出 php

答案:

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

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

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

  1. $str=”1234567890”;
  2. function test($str){
  3. $foo=Strlen($str);
  4. $s=””;
  5. $n=0;
  6. for($i=$foo-1;$i>=0,$i--){
  7. $s=$str[$i].$s;
  8. $n++;
  9. if($n>3){
  10. $s=”,”.$s;
  11. $n=1;
  12. }
  13. }
  14. return trim($s,”,”);
  15. }

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

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

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

 

  1. <?php
  2. // @file demo.class.php
  3. class demo {
  4. function __construct() {
  5.  
  6. }
  7. }
  8. // end 到此整个文件结束

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

5、给<a href=”http://www.viphper.com”>PHP学习网</a> 添加事件,点击弹出链接链接地址,而不是跳转

  1. <script>
  2. $(a)click(function(){
  3. alert($(this).attr(‘href’));
  4. })
  5. </script>

6、写一个类实现接口ArrayAccess

  1. Class me implements ArrayAccess{
  2. //重写接口类中的方法
  3.  
  4. }

 

7、分别输出(1)、(2)运行结果,试简述过程。

  1. class sample {
  2. function __call($a, $b){
  3. echo ucwords(implode(' ', $b).' '.$a);
  4. }
  5. function ads(){
  6. ob_start();
  7. echo 'by';
  8. return $this;
  9. }
  10. function ade(){
  11. $c = ob_get_clean();
  12. $this->php('power', $c);
  13. }
  14. }
  15. $inst = new sample();
  16. (1) $inst->viphper('welcome', 'to');
  17. (2) $inst->ads()->ade();

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


关注微信公众号『PHP学习网

第一时间了解最新网络动态
关注博主不迷路~

PHP学习网:站内收集的部分资源来源于网络,若侵犯了您的合法权益,请联系我们删除!
分享到:
赞(0)

文章评论

您需要之后才可以评论
0点赞 0评论 收藏 QQ分享 微博分享

PHP学习网

PHP学习网