dpyoh6553 2012-11-20 16:27
浏览 82
已采纳

获取请求URI PHP

I am struck in getting the URI in my wordpress application and lack of PHP knowledge is making my progress slow. I have this URL

http://abc.com/my-blog/abc/cde 

i need to create a URL something like

http://abc.com/my-blog/added-value/abc/cde

where http://abc.com/my-blog is the URL of my wordpress blog which i can easily get using following method

home_url()

i can use PHP $_SERVER["REQUEST_URI"] to get request URI which will come up as

/my-blog/abc/cde

and than i have no direct way to add value as per my requirement

is there any way to achieve this easily in PHP or Wordpress where i can get following information

  1. Home URL
  2. Rest part of the URL

so that in end i can do following

Home-URL+ custom-value+Rest part of the URL

My point of Confusion

  1. On my local set up $_SERVER["REQUEST_URI"] is giving me /my-blog/abc/cde, where /my-blog is installation directory of wordpress and i can easily skip first level.
  2. On production server its not same as /my-blog will not be part of the URL.
  • 写回答

5条回答 默认 最新

  • dragon012100 2012-11-20 16:40
    关注

    Very briefly:

    <?php
    
    $url = "http://abc.com/my-blog/abc/cde";
    
    $parts = parse_url($url);
    
    $path = explode("/", $parts["path"]);
    array_splice($path, 2, 0, array("added-part")); //This line does the magic!
    
    echo $parts["scheme"] . "://" . $parts["host"] . implode("/",$path);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题