Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing strings from an RSS feed

Status
Not open for further replies.

Baldwin238

Technical User
Feb 23, 2005
68
US
Ok.. This is going to fairly long and complicated (at least for me).

The long and short of it....I am taking a feed and putting it onto my site at ( The feed (or a portion of it) is here:
Code:
- <tournament>
  <time>12:15 AM</time> 
  <type>No Limit Texas Holdem</type> 
  <payout>$50</payout> 
  <sitename>Absolute Poker</sitename> 
  <sitelink>[URL unfurl="true"]http://www.xxxx.com/fclick/fclick.php?fid=absolute</sitelink>[/URL] 
  </tournament>
- <tournament>
  <time>12:50 AM</time> 
  <type>No Limit Texas Holdem</type> 
  <payout>$1250</payout> 
  <sitename>Party Poker</sitename> 
  <sitelink>[URL unfurl="true"]http://www.xxxx.com/fclick/fclick.php?fid=partypoker</sitelink>[/URL] 
  </tournament>
- <tournament>
  <time>01:00 AM</time> 
  <type>No Limit Texas Holdem</type> 
  <payout>$1000</payout> 
  <sitename>Gaming Club Poker</sitename> 
  <sitelink>[URL unfurl="true"]http://www.xxxx.com/fclick/fclick.php?fid=gamingclub2</sitelink>[/URL] 
  </tournament>

The sections where it says <sitelink> I want to add to my site, but with MY referral links in it. The ones currently there are for a different site.

Can I do an if..then statement with a replace function in there as well? I am an .asp person and am not sure ow to even go about STARTING this. The code I have on my site to get the feed as it is now is...
Code:
<?php 
$file = '[URL unfurl="true"]http://www.freerolls.net/feed.php';[/URL] 
require_once('xml.parser.class.php'); 

$xml = new xml_parser_class(); 
$xml->parseFile($file); 
$tree = $xml->getTree(); 
unset($xml); 

print '<table border="0" cellpadding="2" cellspacing="0" width="" class="tm">';
print '<tr class="caption"><td>Time (Eastern)</td><td>Payouts</td><td>Site</td></tr>';

$i = 0;
foreach($tree['freerolls']['tournament'] as $k)
{
   $i++;
   print '<tr class="'.(!($i%2)?'rl':'rd').'">';
   print '<td>'.$k['time']['value'].'</td>';
   print '<td>'.$k['payout']['value'].'</td>';
   print '<td>'.$k['sitename']['value'].'</td>';
   print '</tr>';
}
print '</table>';

?>

Any suggestions would be greatly appreciated!

Jeff Baldwin
sig2.gif
 
Of course, you can manipulate the content in any way. A simple string manipulation for the links should solve your problem.

You can access the URL as $k['sitelink']['value']. Describe your referral link and we'll help you on the way.
 
My referral link is different for every different ['sitelink'] as the original one is as well. An example of one my links would be:
Code:
[URL unfurl="true"]http://www.example_ref_link.com/main.asp?host=a_77a_11221b_2320[/URL]

This link would of course change being dependant on the [sitename]. Would I need to start a mySQL database of all my links? Making them, for example,
Code:
[URL unfurl="true"]http://www.absolutelyfreerolls.com/ref/refclick.php?fid=example_ref_link[/URL]

Or am I getting too far ahead of myself?


Jeff Baldwin
sig2.gif
 
How many different sites are there?
If it is a manageable number you could keep them in a flat file. If the number is larger, a database solution is recommendable.

But, if I understand correctly, above the only substitution I see is that the new URL has the GET parameter fid as hostname and an attached GET parameter host=a_....
If that is the only thing that needs to be translated, there is no need for a datafile or database.

Code:
$URL = "[URL unfurl="true"]http://www.absolutelyfreerolls.com/ref/refclick.php?fid=example_ref_link";[/URL]
$analyzedURL = parse_url($URL);
# $analyzedURL['query'] holds fid=example_ref_link
preg_match("/fid=(\w*)/",$analyzedURL['query'],$reflink);
print_r($reflink);
$newURL = "[URL unfurl="true"]http://www.".$reflink[/URL][1].".com/main.asp?host=a_77a_11221b_2320";
echo("Before: $URL<br />");
echo("After : $newURL");
 
I think we've deviated from what I was originally asking. The feed is from another site/author. The [sitelink] data in the feed is for his own links. I want those to be replaced with my links. So far I have about 25 different links, with the possibilty of adding more in the future. Every link is completely different. I was thinking of setting up a database which holds MY links and an ID:

TABLE NAME: reflinks
======================================================
| ID | LINKS |
======================================================
|absolute | |
|pokerCS | |
|titan | |
======================================================

Then using the url below to pull the link from the database:
Code:
[URL unfurl="true"]http://www.absolutelyfreerolls.com/reflinks.php?fid=absolute[/URL]

I guess my main question is..how do I replace the FEED AUTHOR's [sitelink] with my own links from the table? I think I understand how, I just dont know how to implement it?

Jeff Baldwin
sig2.gif
 
The steps are:
1. Find the record in the table that corresponds to the original link.
2. Print the proprietary link from the record into the desired space.

The basic steps how to connect, query, and retrieve data from a MySQL server are described in faq434-3850
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top