Warning: Illegal string offset 'echo' in /home4/nitingup/public_html/blog/wp-content/themes/hybrid/library/extensions/custom-field-series.php on line 79

14 responses to “PHP: Relative URL to Absolute URL”

  1. Drupal: FeedAPI Imagegrabber | Public Mind

    [...] for FeedAPI ImageGrabber PHP: Relative URL to Absolute URL Open Source Software and [...]

  2. Geard

    That’s exactly what I need. Thanks,

  3. Jay

    Hi there Nitin I’m testing this class as the script I’m puting together needs the ab/path to function, and wondering if you have any examples, thanks

    1. nitin


      as mentioned, it is very simple to use this function. just include it in your current file and call the function as mentioned above. You can look for the tutorial at nadeausoftware.com or the project i am currently using it in, feedapi imagegrabber.


  4. Tyler Akins

    This function doesn’t really work well for file:/// URLs. For instance, url_to_absolute(‘file:///path/file.html’, ‘image.gif’) returns false. Would you be able to change line 82 a bit so that if the scheme is ‘file’, it won’t require ‘host’?

    (Yeah, I can make the change locally, but I’d rather the change gets back into the main distribution.)

  5. Tyler Akins

    Oh, I’m sorry that I didn’t mention this in my last post, but why don’t you use parse_url() instead of your split_url()? I’m a fan of using built-in functions when possible for speed and because a larger developer base will be continually reviewing its functionality.

  6. Dinar Q.
  7. Dinar Q.

    i have tried to modify this way : function join_url( $parts, $encode=TRUE) – does not help – also does not work.
    it returns empty string, as i remember.

  8. Matt

    This one is way more simple, and even works for parent directories (..) and recognizes base direcories (.):


  9. NubbyNubkins

    I was experimenting with this script to see if my solution was slower and it definitely was. My solution was also far more complex. Thank you very much for offering this invaluable tool.
    I would also like to mention that this script sometimes has a problem dealing with empty values. While this may not often occur for many people, the way I wrote my link spider would result in empty array values when duplicates or non-page links were found. Because of the location within my script where I needed the absolute url conversion, empty values would appear directly prior to this function. The e-warning would occur on line 327: “return $parts”. and directly under the “if (!$decode)”. The simple solution I used was to include:

    if(($var != “”) || (!empty($var))) {url_to_absolute( $baseUrl, $relativeUrl);}

    I just thought you might want to know that there is a potential issue when it concerns empty values.

    1. NubbyNubkins

      My apologies. I forgot to clarify that the solution I used is not in the script itself but when the function is called.

  10. Mohit

    Nice article I have used this PHP Script in my website and I have better performance in SEO also

Leave a Reply

Open Source Projects