php程序员面试题(经典汇总)

原创
2016-07-25 08:59:27 685浏览
  1. function GBsubstr($string, $start, $length) {
  2. if(strlen($string)>$length){
  3. $str=null;
  4. $len=$start+$length;
  5. for($i=$start;$i if(ord(substr($string,$i,1))>0xa0){
  6. $str.=substr($string,$i,2);
  7. $i++;
  8. }else{
  9. $str.=substr($string,$i,1);
  10. }
  11. }
  12. return $str.'...';
  13. }else{
  14. return $string;
  15. }
  16. }
复制代码

2.用PHP写出显示客户端IP与服务器IP的代码? 答:

  1. $readcontents = fopen("http://bbs.it-home.org/index.html", "rb");
  2. $contents = stream_get_contents($readcontents);
  3. fclose($readcontents);
  4. echo $contents;
复制代码

方法2:

  1. function getExt($url){
  2. $arr = parse_url($url);
  3. $file = basename($arr['path']);
  4. $ext = explode(".",$file);
  5. return $ext[1];
  6. }
复制代码

答案2:

  1. function getExt($url) {
  2. $url = basename($url);
  3. $pos1 = strpos($url,".");
  4. $pos2 = strpos($url,"?");
  5. if(strstr($url,"?")){
  6. return substr($url,$pos1 + 1,$pos2 - $pos1 - 1);
  7. } else {
  8. return substr($url,$pos1);
  9. }
  10. }
复制代码

19. 写一个函数,算出两个文件的相对路径?   如 $a = '/a/b/c/d/e.php';   $b = '/a/b/12/34/c.php';   计算出 $b 相对于 $a 的相对路径应该是 http://bbs.it-home.org/c/d将()添上 答:

  1. function getRelativePath($a, $b) {
  2. $returnPath = array(dirname($b));
  3. $arrA = explode('//m.sbmmt.com/m/', $a);
  4. $arrB = explode('//m.sbmmt.com/m/', $returnPath[0]);
  5. for ($n = 1, $len = count($arrB); $n if ($arrA[$n] != $arrB[$n]) {
  6. break;
  7. }
  8. }
  9. if ($len - $n > 0) {
  10. $returnPath = array_merge($returnPath, array_fill(1, $len - $n, '..'));
  11. }
  12. $returnPath = array_merge($returnPath, array_slice($arrA, $n));
  13. return implode('//m.sbmmt.com/m/', $returnPath);
  14. }
  15. echo getRelativePath($a, $b);
复制代码

希望以上为大家提供的php面试题,对大家有所帮助,真诚期待在您的应聘中可以用得上。



声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。