Jump to content


Photo

Printing everything twice


  • Please log in to reply
4 replies to this topic

#1 Attro

Attro
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 July 2006 - 01:42 PM

I'm trying to grab an RSS feed and strip the "[category]" crap out of the title and then fix the download link to point to the file instead of the page.  That much works but it's printing every line twice.  If I just do one or the other it works like it should and doesn't even double up the stuff that it's fixed.

<?php
header("Content-type: text/xml");

$link = "http://www.torrentspy.com/rss.asp?";
if ($_GET['mode']) $link .= "mode=". $_GET['mode']. "&";
if ($_GET['id']) $link .= "id=". $_GET['id']. "&";
if ($_GET['db']) $link .= "db=". $_GET['db']. "&";
if ($_GET['query']) $link .= "query=". $_GET['query']. "&";

$lines = file($link);

foreach ($lines as $line_num => $line) {
    echo ereg_replace("<title>\[.*\].(.*)<\/title>", "<title>\\1</title>", $line);
	echo ereg_replace("<link>http:\/\/www.torrentspy.com\/torrent\/(.*)\/.*<\/link>", "<link>http://www.torrentspy.com/download.asp?id=\\1</link>", $line);
}
?>


#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 25 July 2006 - 02:10 PM

You are echoing each replace. Try this:

foreach ($lines as $line_num => &$line) {
  ereg...
  ereg...
  echo $line;
}

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Attro

Attro
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 July 2006 - 02:43 PM

No more doubling up :) but now ereg_replace doesn't seem to want to do any replacing.

Here's what I have now if it helps:
...
foreach ($lines as $line_num => &$line) {
  ereg_replace("<title>\[.*\].(.*)<\/title>", "<title>\\1</title>", $line);
  ereg_replace("<link>http:\/\/www.torrentspy.com\/torrent\/(.*)\/.*<\/link>", "<link>http://www.torrentspy.com/download.asp?id=\\1</link>", $line);
  echo $line;
}
...

Thanks for the help btw.

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 25 July 2006 - 03:18 PM

I thought the reference might do it, but you'll have to assign:

$line = ereg...
$line = ereg...
echo $line;

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 Attro

Attro
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 July 2006 - 03:29 PM

That worked.  Thanks so much.  :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users