...

View Full Version : collecting values in array from tags ??



PHPycho
11-26-2007, 06:01 AM
Hello forums.
Supppose i had following format in a string

$string = '<tag value="1">Name1</tag>
<tag value="2">Name2</tag>
:
:
<tag value="n">Namen</tag>';

I would like to collect those values and names in an array as

$array['name'] = array('Name1', 'Name2', .., 'Namen');
$array['value'] = array('1', '2', .., 'n');

Any suggestions and hints are warmly welcome.

Inigoesdr
11-26-2007, 06:21 AM
$string = '<tag value="1">Name1</tag>
<tag value="2">Name2</tag>
:
:
<tag value="n">Namen</tag>';

$return = preg_match_all('/<tag\s+value="(.*?)">(.*?)<\/tag>/', $string, $matches, PREG_PATTERN_ORDER);
$array['name'] = $matches[2];
$array['value'] = $matches[1];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum