converting to a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CantonDog
Forum Newbie
Posts: 13
Joined: Wed Dec 03, 2003 11:59 am
Location: Denver, CO

converting to a variable

Post by CantonDog »

I haven't exactly cracked the XML barrier yet...

If I've got a URL that will spit out XML for me... how can I put the data between the <tags> into a variable to be used in the rest of my php script? The var I want is in the middle of the XML code.

example:

// bunch of XML code
<tag_im_looking_for>Var I need</tag_im_looking_for>
// rest of XML

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use the xml parsing helper functions, or use a regular expression to fetch the tag if you want just a ghetto solution.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Code: Select all

<?php
$source = '<tag>tag soup</tag>';
preg_match_all('#<tag>(.+?)</tag>#', $source, $output);
print $output['0']; //tag soup
?>
Post Reply