久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將域名后的所有內(nèi)容都變成字符串

How to get everything after the domain name into a string(如何將域名后的所有內(nèi)容都變成字符串)
本文介紹了如何將域名后的所有內(nèi)容都變成字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的目標是將域名后的所有內(nèi)容都變成一個字符串.就像在 mysite.com/page/page2 中一樣,會產(chǎn)生一個字符串page/page2".我可以做到,但是它開始給我?guī)韱栴},例如,當站點位于子文件夾中而不是根目錄中時,站點所在的文件夾也將包含在字符串中,如果我不使用 mod_rewrite獲得漂亮的鏈接,它還會將 index.php 添加到字符串中.

因此,我需要一兩個技巧來讓腳本了解該站點是否位于諸如 mysite.com/sitefolder/page/page2 之類的子文件夾中,并且它仍然會產(chǎn)生一個字符串

page/page2

如果站點沒有使用mod_rewrite并且url是mysite.com/sitefolder/index.php/page/page2,它仍然會產(chǎn)生一個字符串

page/page2

請記住,我在配置文件中定義了 URL 和 USE_MOD_REWRITE,所以不需要魔法.我只是不知道如何獲取該字符串.我知道我可以執(zhí)行 $_SERVER['REQUEST_URI'] 來獲取字符串,但是 index.php 仍然會在其中.如果我解釋得不夠好,我很抱歉,但感謝所有幫助.

解決方案

  • 解析請求uri獲取路徑
  • 從字符串的末尾刪除最終的腳本名稱(例如 index.php)
  • 刪除任何尾部斜杠

    <前>$request = parse_url($_SERVER['REQUEST_URI']);$path = $request["path"];$result = rtrim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');

編輯

$request = parse_url($_SERVER['REQUEST_URI']);$path = $request["path"];$result = trim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');$result =explode('/', $result);$max_level = 2;而 ($max_level < count($result)) {未設(shè)置($result[0]);}$result = '/'.implode('/', $result);

My goal is to get everything after the domain name into a string. As in mysite.com/page/page2 would result in a string "page/page2". That I can do, however it starts giving me problems when, for example, the site is in a subfolder and not in root, then the folder the site is in will also be included in the string and if I'm not using mod_rewrite to get pretty links, it will also add index.php to the string.

So, I would need a trick or two to make the script understand whether or not the site is in a subfolder such as mysite.com/sitefolder/page/page2 and that it would still result in a string

page/page2

If the site doesn not use mod_rewrite and the url is mysite.com/sitefolder/index.php/page/page2, it would still result in a string

page/page2

Keep in mind that I have URL and USE_MOD_REWRITE defined in a config file, so no need for magic. I just have no idea how to go about getting that string. I know I could do $_SERVER['REQUEST_URI'] to get the string, but then index.php would still be in it. I'm sorry if I didn't explain well enough, but all help is appreciated.

解決方案

  • get the path by parsing the request uri
  • remove eventual script name from the end of the string (e.g. index.php)
  • rtrim any trailing slashes

    $request = parse_url($_SERVER['REQUEST_URI']);
    $path = $request["path"];
    $result = rtrim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');
    

EDIT

$request = parse_url($_SERVER['REQUEST_URI']);
$path = $request["path"];

$result = trim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');

$result = explode('/', $result);
$max_level = 2;
while ($max_level < count($result)) {
    unset($result[0]);
}
$result = '/'.implode('/', $result);

這篇關(guān)于如何將域名后的所有內(nèi)容都變成字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網(wǎng)站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 99免费视频| 日韩欧美在线观看 | 成人精品一区二区三区中文字幕 | 亚洲日本免费 | 欧美在线一区二区三区 | 亚洲免费视频在线观看 | 天天干 夜夜操 | 国产日韩欧美电影 | 欧美视频一区二区三区 | 午夜视频在线播放 | 天堂一区 | 国产日韩欧美精品 | 一级一级毛片免费看 | 国产香蕉视频 | 中文字幕一区在线 | 日本精品视频一区二区 | 亚洲xx在线 | 91精品国产综合久久久久久丝袜 | 一本大道久久a久久精二百 欧洲一区二区三区 | 日韩欧美大片在线观看 | 久久久国产精品视频 | 天天干狠狠操 | 午夜免费观看 | 中文字幕1区2区3区 日韩在线视频免费观看 | 欧美黄色一区 | 欧美一区二区三区四区在线 | 欧美激情精品久久久久 | 国产精品99久久久久久动医院 | 成人一区二区三区 | 国产一区二区在线播放 | 成人精品久久 | 91视频在线| 久草视频在线播放 | 国产免费一区二区 | 99精品欧美一区二区三区综合在线 | 极品的亚洲 | av中文网 | 一区二区三区av | 国产日韩精品视频 | 欧美在线二区 | 久久精品亚洲一区二区三区浴池 |