Re: RSS / eregi_replace()

From: Date: Tue, 03 Aug 2004 22:49:30 +0000
Subject: Re: RSS / eregi_replace()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-192631@lists.php.net to get a copy of this message
On Tue, 3 Aug 2004 18:36:02 -0400, Anthony Ritter <tony@gonefishingguideservice.com> wrote: > Greetings, > > I'm using an RSS feed from the New York Times and right now the a href link > takes the user to the same window. > > I'd like the link to open in it's own window by using the target .html > attribute. > > I was hoping that I could use the eregi_replace() call by inserting: > > <a > href="http://\\0">target="_blank">\\0</a> > > where it matches any character between the <link></link> string in the URL. > > However it is not working for me. > > Viewing the xhtml of thr NY Times feed below, there are many areas of > <links></links> so I'm not sure whether this is the correct way to go. > > Any leads or assistance will be greatly appreciated. > > TR > ................... > > <? > > $string="<link>http://www.nytimes.com/2004/08/03/national/03tape.html? > ex=1249272000&en=484f82ff258ab8c7&ei=5088&partner=rssnyt</link>"; // the > string URL > > $pattern = "^(<link>.+</link>)$"; //match any character between the > <link> > and <link> > > $replace_pattern= '<a href="http://\\0" > \b�1¬Ôó('�löþ>target="_blank">\\0</a>'; > > $new_string=eregi_replace($pattern,$replace_pattern,$string); > > echo $new_string; > ?> > ................. > > // snippet of NYTimes RSS feed > > > <link>http://www.nytimes.com/2004/08/03/politics/03intel.html?ex=1249272000& > en=e061516bea792668&ei=5088&partner=rssnyt</link> > <description>Much of the information that led to the new terror alert was > three or four years old, but even the dated evidence was > troubling.</description> > <author>By DOUGLAS JEHL and DAVID JOHNSTON</author> > <pubDate>Tue, 03 Aug 2004 00:00:00 EDT</pubDate> > </item> > - <item> > <title>Tape of Kennedy's Killing Is Getting Digital Analysis</title> > > <link>Tþl>,@{ > ºPäÖ÷Ý€http://www.nytimes.com/2004/08/03/national/03tape.html?ex=1249272000&e > n=484f82ff258ab8c7&ei=5088&partner=rssnyt</link> > Thanks, lots of good info here. It's nice to have all of the info at once. I don't know about eregs myself, but I'll try a preg solution: $new_text = preg_replace('!<link>(.*?)</link>!', '<a href="\1" target="_blank">\1</a>', $text); -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#192631) next »