Combining an absolute and relative Url

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Cybernet

    #1

    Combining an absolute and relative Url

    Is there any function for combining an absolute and a relative URL to result
    in an absolute URL?
    Like if I have http://www.domain.com and "../images/1.jpeg" it will evaluate
    to http://www.domain.com/images/1.jpeg.

    I know WinInet for windows has a function that does this called
    InternetCombine Url, I just need the same function in PHP


  • CountScubula

    #2
    Re: Combining an absolute and relative Url

    "Joe Cybernet" <no@no.ie> wrote in message
    news:O3jLb.4067 $HR.8512@news.i ndigo.ie...[color=blue]
    > Is there any function for combining an absolute and a relative URL to[/color]
    result[color=blue]
    > in an absolute URL?
    > Like if I have http://www.domain.com and "../images/1.jpeg" it will[/color]
    evaluate[color=blue]
    > to http://www.domain.com/images/1.jpeg.
    >
    > I know WinInet for windows has a function that does this called
    > InternetCombine Url, I just need the same function in PHP
    >
    >[/color]


    strAbs = strDom & strURI

    --
    Mike Bradley
    http://www.gzentools.com -- free online php tools


    Comment

    • CountScubula

      #3
      Re: Combining an absolute and relative Url

      "Joe Cybernet" <no@no.ie> wrote in message
      news:O3jLb.4067 $HR.8512@news.i ndigo.ie...[color=blue]
      > Is there any function for combining an absolute and a relative URL to[/color]
      result[color=blue]
      > in an absolute URL?
      > Like if I have http://www.domain.com and "../images/1.jpeg" it will[/color]
      evaluate[color=blue]
      > to http://www.domain.com/images/1.jpeg.
      >
      > I know WinInet for windows has a function that does this called
      > InternetCombine Url, I just need the same function in PHP
      >
      >[/color]
      oops, I thought I was in the comp.lang.basic .visual, direagard my last post

      $absURL = $dom . $URI;

      --
      Mike Bradley
      http://www.gzentools.com -- free online php tools


      Comment

      • Chung Leong

        #4
        Re: Combining an absolute and relative Url

        There's no built-in function that does that. Here's one that should join
        there correctly:

        function InternetCombine Url($absolute, $relative) {
        extract(parse_u rl($absolute));
        if($relative{0} == '/') {
        $cparts = array_filter(ex plode("/", $relative));
        }
        else {
        $aparts = array_filter(ex plode("/", $path));
        $rparts = array_filter(ex plode("/", $relative));
        $cparts = array_merge($ap arts, $rparts);
        foreach($cparts as $i => $part) {
        if($part == '.') {
        $cparts[$i] = null;
        }
        if($part == '..') {
        $cparts[$i - 1] = null;
        $cparts[$i] = null;
        }
        }
        $cparts = array_filter($c parts);
        }
        $path = implode("/", $cparts);
        $url = "";
        if($scheme) {
        $url = "$scheme://";
        }
        if($user) {
        $url .= "$user";
        if($pass) {
        $url .= ":$pass";
        }
        $url .= "@";
        }
        if($host) {
        $url .= "$host/";
        }
        $url .= $path;
        return $url;
        }

        echo InternetCombine Url("http://www.domain.com" , "../images/1.jpeg");

        Uzytkownik "Joe Cybernet" <no@no.ie> napisal w wiadomosci
        news:O3jLb.4067 $HR.8512@news.i ndigo.ie...[color=blue]
        > Is there any function for combining an absolute and a relative URL to[/color]
        result[color=blue]
        > in an absolute URL?
        > Like if I have http://www.domain.com and "../images/1.jpeg" it will[/color]
        evaluate[color=blue]
        > to http://www.domain.com/images/1.jpeg.
        >
        > I know WinInet for windows has a function that does this called
        > InternetCombine Url, I just need the same function in PHP
        >
        >[/color]


        Comment

        • John Dunlop

          #5
          Re: Combining an absolute and relative Url

          Joe Cybernet wrote:
          [color=blue]
          > Is there any function for combining an absolute and a relative URL to result
          > in an absolute URL?[/color]

          As has already been said, there isn't a built-in function for
          resolving relative URLs. However, you might follow the algorithm set
          out in RFC2396 sec. 5.2. Watch out if you're using parse_url, as it
          parses some relative URLs incorrectly.

          --
          Jock

          Comment

          Working...