Search code examples
phpphpbb3

PHP - Function to remove character and concatenate another (aka converting relative to absolute url)


I have a phpbb external script which outputs a relative url

(like ./forum/viewtopic.php?f=xx&t=xx),

but for making an rss feed I need the absolute url

(http://example.com/forum/viewtopic.php?f=xx&t=xx) to use.

My question is: How could I make this?

I suppose it should just be a string function, to replace the first dot and then concatenate the http://example.com before it, but I don't have enough php skills to do that.


Solution

  • Simply replace your ./ with the hostname.

    $url = str_replace('./', 'http://example.com/', $url);