Rewriting RSS URL's on the fly....

Status
Not open for further replies.

bam bam

New member
Oct 9, 2007
962
11
0
Is it possible to take an RSS feed, rewrite the URL's inside it and output it as an RSS feed again?

If so, how?
 


heh no regex required

Code:
<?php

$feedUrl = 'http://feeds.feedburner.com/nickycakes';
$rawFeed = file_get_contents($feedUrl);
$xml = new SimpleXmlElement($rawFeed);

$i=0;
foreach($xml->channel->item as $item){
  $xml->channel->item[$i]->link =  "http://www.google.com";
  $xml->channel->item[$i]->guid =  "http://www.google.com";
  $i++;
}

echo $xml->asXML();

?>
 
OK kool, thanks cakes.

Would i use the same thing if i just wanted to add my aff link to the end of the URL instead of rewriting the entire thing?
 
bam, yeah just do this:
heh no regex required

Code:
<?php

$feedUrl = 'http://feeds.feedburner.com/nickycakes';
$rawFeed = file_get_contents($feedUrl);
$xml = new SimpleXmlElement($rawFeed);

$i=0;
foreach($xml->channel->item as $item){
  $xml->channel->item[$i]->link .=  "affid=me";
  $xml->channel->item[$i]->guid .=  "affid=me";
  $i++;
}

echo $xml->asXML();

?>
 
I'm a n00b at this but here it goes:

test.rss: <link>http://www.test.com/test.php?affiliate123</link>

PHP:
<?php

$data = file_get_contents('test.rss');

$regex = '/<link>(.+?)\?/si';

preg_match_all($regex,$data,$link);


for($i = 0; $i < count($link[1]); $i++) {


    $cleanlink = $link[1][$i];

    $cleanlink .= '?bambam';

    echo $cleanlink;

}

?>
 
This is working:

PHP:
<?php

$feedUrl = 'http://feeds.feedburner.com/nickycakes';
$rawFeed = file_get_contents($feedUrl);
$xml = new SimpleXmlElement($rawFeed);

$i=0;
foreach($xml->channel->item as $item){

  $temp = $xml->channel->item[$i]->link;


  $regex = '/http(.+?)com/';
  preg_match($regex,$temp,$xx);

  $xx[0] .= '/bambam/';
  
  $xml->channel->item[$i]->link = $xx[0];


  $xml->channel->item[$i]->guid =  $xx[0];
  $i++;


}

echo $xml->asXML();

?>
 
Status
Not open for further replies.