Page 1 of 1

converting to a variable

Posted: Thu Aug 04, 2005 4:09 pm
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

Posted: Thu Aug 04, 2005 5:13 pm
by feyd
use the xml parsing helper functions, or use a regular expression to fetch the tag if you want just a ghetto solution.

Posted: Thu Aug 04, 2005 5:24 pm
by bokehman

Code: Select all

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