You are here: Re: [PHP] Easy way to grab a value out of XML? « PHP « IT news, forums, messages
Re: [PHP] Easy way to grab a value out of XML?

Posted by emre on 12/18/29 11:12

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:

<?php
$str="<xml version bla
bla><price>somevaluehere</price><price>somevaluehere2</price><price>somevaluehere2</price>etc";

preg_match_all("/<price>([^<])*<\/price>/i", $str, $matches);
echo count($matches[0]);
for ($i=0; $i< count($matches[0]); $i++) {
echo '<br> + '.$matches[0][$i];
}
?>

but you'd better learn to handle xml files via xml parsers.











----- Original Message -----
From: "Brian Dunning" <brian@briandunning.com>
To: <php-general@lists.php.net>
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 <price>x.xx</price>. 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
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация