Forum Moderators: coopster

Message Too Old, No Replies

collecting values in array from tags?

         

PHPycho

6:01 am on Nov 26, 2007 (gmt 0)

10+ Year Member



Hello forums.
Supppose i had following format in a string
[PHP]$string = '<tag value="1">Name1</tag>
<tag value="2">Name2</tag>
:
:
<tag value="n">Namen</tag>';[/PHP]

I would like to collect those values and names in an array as
[PHP]$array['name'] = array('Name1', 'Name2', .., 'Namen');
$array['value'] = array('1', '2', .., 'n');[/PHP]

Any suggestions and hints are warmly welcome.

sandy103

6:55 am on Nov 26, 2007 (gmt 0)

10+ Year Member



I can suggest two methods for this. Either you can use the regular expression and find the name between the open tag and the close tag and also find the find attribute of the tag to get the value. Another option can be to use any xml parser logic.