/    Sign up×
Community /Pin to ProfileBookmark

PHP & RSS File Issue

I’m having a little issue reading an XML file…

Let’s say that I have a XML file like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<channel>
<item>
<tag1>….</tag1>
<tag2>….</tag2>
<tag3>….</tag3>

<[COLOR=”Red”]specialtag[/COLOR] [COLOR=”Purple”]url[/COLOR]=”http://something.mp3” />
<[COLOR=”Red”]specialtag[/COLOR] [COLOR=”Purple”]url[/COLOR]=”http://something.jpg” />

</item>
</channel>

Well, I want to get access to the url in the “specialtag” with the .jpg extension. I would think that you have to reference the “specialtag”, save it to variable/object, and loop through the variable because it would be an array…but for some reason this isn’t correct…

what I have so far is this:

[code=php]
$image_location;
$img_count=0;
$enclosure_tags = $item -> enclosure;

foreach ($enclosure_tags as $tag){

$all_attributes = $tag -> attributes();

foreach ($all_attributes as $a => $b){

if ( ($a==”url”) && (preg_match(“/(.jpg)(.)*||(.png)(.)*/i”, $b)) )
{
if ($img_count == 0){

$image_location=$b;
$img_count++;
}

}

}
}
[/code]

..where “enclosure” would represent “specialtag”…

when I reference $item -> enclosure, I’m not getting an array…

why is that?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 17.2010 — It might help to do a print_r() or var_dump() of $item to see what it's structure is.
Copy linkTweet thisAlerts:
@ChuckBauthorOct 17.2010 — It might help to do a print_r() or var_dump() of $item to see what it's structure is.[/QUOTE]


appreciate it..will try it out...thanks...
×

Success!

Help @ChuckB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...