Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    collecting values in array from tags ??

    Hello forums.
    Supppose i had following format in a string
    PHP Code:
    $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
    PHP Code:
    $array['name'] = array('Name1''Name2', .., 'Namen');
    $array['value'] = array('1''2', .., 'n'); 
    Any suggestions and hints are warmly welcome.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    $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$matchesPREG_PATTERN_ORDER);
    $array['name'] = $matches[2];
    $array['value'] = $matches[1]; 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •