Re: [PHP] Easy way to grab a value out of XML?
On Fri, April 1, 2005 1:53 pm, Brian Dunning said: > I've been looking at the XML commands and am feeling a bit overwhelmed. > My needs are simple and I'm hoping there's an easy solution that I'm > just missing. I have a hunk of well-formed XML in a variable, $xml, and > it contains only one instance of x.xx. I just want to > get the $price out of $xml. What's the simplest way? Simplest? $xml = file_get_contents('...'); $parts = explode('', $xml); $price = $parts[1]; $parts = explode('', $price); $price = $parts[0]; XML fans now all want to kill me, but there it is. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Easy way to grab a value out of XML?
Brian Dunning wrote: I've been looking at the XML commands and am feeling a bit overwhelmed. My needs are simple and I'm hoping there's an easy solution that I'm just missing. I have a hunk of well-formed XML in a variable, $xml, and it contains only one instance of x.xx. I just want to get the $price out of $xml. What's the simplest way? $xml = ""; preg_match_all("|(.*?)|mi",$xml,$results); echo $results[1]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Easy way to grab a value out of XML?
The XML functions really aren't that hard to use. If you just want a simple parse to pick out something have a look at: for PHP4: http://php.net/xml_parse_into_struct for PHP5: http://php.net/simplexml_load_file -Rasmus [EMAIL PROTECTED] wrote: you can handle xml output as if a string file, then easily parse xml file with preg_match / preg_match_all, smt like this can do the job: $str="somevalueheresomevaluehere2somevaluehere2etc"; preg_match_all("/([^<])*<\/price>/i", $str, $matches); echo count($matches[0]); for ($i=0; $i< count($matches[0]); $i++) { echo ' + '.$matches[0][$i]; } ?> but you'd better learn to handle xml files via xml parsers. - Original Message - From: "Brian Dunning" <[EMAIL PROTECTED]> To: Sent: Friday, April 01, 2005 11:53 PM Subject: [PHP] Easy way to grab a value out of XML? I've been looking at the XML commands and am feeling a bit overwhelmed. My needs are simple and I'm hoping there's an easy solution that I'm just missing. I have a hunk of well-formed XML in a variable, $xml, and it contains only one instance of x.xx. I just want to get the $price out of $xml. What's the simplest way? - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Easy way to grab a value out of XML?
you can handle xml output as if a string file, then easily parse xml file with preg_match / preg_match_all, smt like this can do the job: $str="somevalueheresomevaluehere2somevaluehere2etc"; preg_match_all("/([^<])*<\/price>/i", $str, $matches); echo count($matches[0]); for ($i=0; $i< count($matches[0]); $i++) { echo ' + '.$matches[0][$i]; } ?> but you'd better learn to handle xml files via xml parsers. - Original Message - From: "Brian Dunning" <[EMAIL PROTECTED]> To: Sent: Friday, April 01, 2005 11:53 PM Subject: [PHP] Easy way to grab a value out of XML? I've been looking at the XML commands and am feeling a bit overwhelmed. My needs are simple and I'm hoping there's an easy solution that I'm just missing. I have a hunk of well-formed XML in a variable, $xml, and it contains only one instance of x.xx. I just want to get the $price out of $xml. What's the simplest way? - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Easy way to grab a value out of XML?
If you are using PHP5 check out SimpleXML (http://php.net/simplexml) On Apr 1, 2005 10:53 PM, Brian Dunning <[EMAIL PROTECTED]> wrote: > I've been looking at the XML commands and am feeling a bit overwhelmed. > My needs are simple and I'm hoping there's an easy solution that I'm > just missing. I have a hunk of well-formed XML in a variable, $xml, and > it contains only one instance of x.xx. I just want to > get the $price out of $xml. What's the simplest way? > > - Brian > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Easy way to grab a value out of XML?
I've been looking at the XML commands and am feeling a bit overwhelmed. My needs are simple and I'm hoping there's an easy solution that I'm just missing. I have a hunk of well-formed XML in a variable, $xml, and it contains only one instance of x.xx. I just want to get the $price out of $xml. What's the simplest way? - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php