• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

help w/ PHP function?

iamme

Lifer
i'm trying to figure this out myself, but i'm stuck 🙁

what i'm trying to do is take an rss feed and extract just the image and URL. here's an example feed:

http://sports.yahoo.com/nba/teams/lal/photos/rss.xml

the description tag has a link to the jpg, link to a full sized version, and a rather long comment. i'm trying to use the preg_replace() php function to extract everything between the <a href></a> tags, which should give me the pic and link to the full sized version. can anyone help me? 😱
 
Dude, This belongs in the dedicated Programming forum...

Oh wait, we don't have one of those... But still, Software would work too... more or less.
 
You wouldn't really want to use preg_replace here, unless you're using the big hammer for a little nail technique, as the only way to use that function would be to attempt to remove everything except your target strings. Since this data has more than one set of <a> tags you will need more than just one function... you can:

Use a for/while loop until no instance is found
Use a split function and a foreach loop of the array

Either way, within one of those you can more easily use substr() to get a specific string you desire, using preg is not necessary as the strings are predictable.

If you're interested in this method, I could do a mock up for you.
 
Hey iamme,

By far the most reliable script you can write here would make use of the simplexml_load_file() function. It'd load the page in and turn it into a PHP object, which you can easily parse to get the image and URL. The code below should be pretty much what you're after.

Edit: I should note that the SimpleXML extension requires PHP 5.
 
Back
Top