亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1882 | 回復(fù): 2
打印 上一主題 下一主題

php有獲得絕對地址的函數(shù)嗎? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2006-05-14 00:13 |只看該作者 |倒序瀏覽
比如想獲得

http://csdn.net/expert/001/./../../example.php

的絕對地址
http://csdn.net/example.php

再者,具體容錯性

http://csdn.net/../../../../index.php
獲得其的真實地址http://csdn.net/../../../../index.php

想得到上述答案該用什么函數(shù)呢?

論壇徽章:
1
技術(shù)圖書徽章
日期:2013-12-05 23:25:45
2 [報告]
發(fā)表于 2006-05-14 11:54 |只看該作者
這個相對的關(guān)系恐怕不是那么好獲得的!

一個簡單的例子:如果服務(wù)器設(shè)置了虛擬目錄怎么辦?
或者符號鏈接怎么辦?

一般自己寫一個析構(gòu)就可以分析了。

論壇徽章:
0
3 [報告]
發(fā)表于 2006-05-14 12:45 |只看該作者
手冊上抄一段給你,應(yīng)該可用.


  1. carlosreche at yahoo dot com
  2. 16-Dec-2004 07:52
  3. In my last function, it will always discard "../" if there are no more parent dirs to go back. But it's a mistake! For example, relative paths like "../../downloads" returns "downloads/", and it should return exactly the same entry (because parent directories for "downloads" may exist in this case). Well, I've corrected this bug. Now:

  4. "C:/downloads/../../../" returns "C:/"
  5. "downloads/../../../"  returns  "../../"

  6. <?php

  7. function real_path($path)
  8. {
  9.    if ($path == "")
  10.    {
  11.        return false;
  12.    }

  13.    $path = trim(preg_replace("/\\\\/", "/", (string)$path));

  14.    if (!preg_match("/(\.\w{1,4})$/", $path)  &&  
  15.        !preg_match("/\?[^\\/]+$/", $path)  &&  
  16.        !preg_match("/\\/$/", $path))
  17.    {
  18.        $path .= '/';
  19.    }

  20.    $pattern = "/^(\\/|\w:\\/|https?:\\/\\/[^\\/]+\\/)?(.*)$/i";

  21.    preg_match_all($pattern, $path, $matches, PREG_SET_ORDER);

  22.    $path_tok_1 = $matches[0][1];
  23.    $path_tok_2 = $matches[0][2];

  24.    $path_tok_2 = preg_replace(
  25.                    array("/^\\/+/", "/\\/+/"),
  26.                    array("", "/"),
  27.                    $path_tok_2);

  28.    $path_parts = explode("/", $path_tok_2);
  29.    $real_path_parts = array();

  30.    for ($i = 0, $real_path_parts = array(); $i < count($path_parts); $i++)
  31.    {
  32.        if ($path_parts[$i] == '.')
  33.        {
  34.            continue;
  35.        }
  36.        else if ($path_parts[$i] == '..')
  37.        {
  38.            if (  (isset($real_path_parts[0])  &&  $real_path_parts[0] != '..')
  39.                || ($path_tok_1 != "")  )
  40.            {
  41.                array_pop($real_path_parts);
  42.                continue;
  43.            }
  44.        }

  45.        array_push($real_path_parts, $path_parts[$i]);
  46.    }

  47.    return $path_tok_1 . implode('/', $real_path_parts);
  48. }

  49. ?>
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP