Heim  >  Artikel  >  Backend-Entwicklung  >  php程序员面试题(经典汇总)

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

WBOY
WBOYOriginal
2016-07-25 08:59:27944Durchsuche
  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('/', $a);
  4. $arrB = explode('/', $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('/', $returnPath);
  14. }
  15. echo getRelativePath($a, $b);
复制代码

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



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn