You are here: Re: [PHP] Problem with SimpleXML « PHP « IT news, forums, messages
Re: [PHP] Problem with SimpleXML

Posted by "Richard Lynch" on 08/25/05 11:47

On Wed, August 24, 2005 3:20 am, Uroš Gruber wrote:
> I have XML and I would like to set some values. I almost done the
> whole
> thing but have some problems when looping through some tags
>
> <foo>
> <bar id="1" name="bar1" />
> <bar id="2" name="bar2" />
> ...
> </foo>
>
> I would like to set value for tag "bar" in some loop and then export
> this back to XML. Is this even possible or it's better to use
> SimpleXML
> only for read and create new XML from it.
>
> XML is about 20 rows of data and I'm using PHP 5.0.4 with all XML
> included.

Maybe PHP 5 + SimpleXML really is that simple, but...

For 20 lines of text, you could probably write a function with explode
and implode and have it done in an hour...

<?php
$bars = explode("<bar", $text);
while (list(, $bar) = each($bars)){
preg_match('/.*id="(.*)" name="(.*)".*/', $bar, $parts);
$id = $parts[1];
$name = $parts[2];
//Do whatever you want with id and name and:
echo "<bar id=\"$id\" name=\"$name\" />\n";
}
?>

--
Like Music?
http://l-i-e.com/artists.htm

 

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

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