Use PHP to Fix Relative URLs in my RSS Feed

Is there a tutorial or function somewhere that can go through an RSS feed as it’s being created (with PHP) and fix any relative urls it finds in the description tag?

I want /thispage.htm to become http://www.mysite.com/thispage

Feed validator spotted the problem and suggested i fix it.

Cheers
Ryan

Something like this do the trick for you?


//This line for demonstration only -Use as you wish
$Url = '/thispage.htm';

//Check the 1st character in the url string - if it is a /
if ($Url[0] == '/')
   {
   //Replace the / with the domain
   $Url = str_replace('/', 'http://www.mysite.com/', $Url);
   }

//Output the url
print $Url;

And if your URL’s are in the text: use preg_replace_callback to call the above script

Ah yeah, it is in text. But couldn’t I just use str_replace on the entire text with same effect?

Cheers
Ryan

I don’t see any reason why not. You’ve have to be careful though and supply the full page of each item - thispage.htm that page.htm etc. You’d need to know in advance what you’re searching for though because otherwise even text that contains the \ would be replaced.