SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expression help?

    $pattern = '/<Insurers>(.*)<\/Insurers\>/';
    preg_match_all($pattern, $xml, $matches);

    print_r($matches);

    i have a xml string from which i want to extract all <insurer> in different part of string..
    .
    .
    .
    <xs:schema id="Insurers" xmlns="" xmlnss="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-comml-msdata">
    </xs:schema>
    - <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-comml-msdata" xmlns:diffgr="urn:schemas-microsoft-comml-diffgram-v1">
    <Insurers>
    <Insurer diffgr:id="Insurer10" msdata:rowOrder="0">
    <insurer>AdfgfA</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer20" msdata:rowOrder="1">
    <insurer>AEdfgg</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer30" msdata:rowOrder="2">
    <insurer>345345</insurer>
    </Insurer>
    </Insurers>
    .
    .


    i want only

    <Insurers>
    <Insurer diffgr:id="Insurer10" msdata:rowOrder="0">
    <insurer>AdfgfA</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer20" msdata:rowOrder="1">
    <insurer>AEdfgg</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer30" msdata:rowOrder="2">
    <insurer>345345</insurer>
    </Insurer>
    </Insurers>

    how can i do this??

  2. #2
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php
    
    $xml = <<<EOD
    <xs:schema id="Insurers" xmlns="" xmlnss="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-comml-msdata">
    </xs:schema>
    - <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-comml-msdata" xmlns:diffgr="urn:schemas-microsoft-comml-diffgram-v1">
    <Insurers>
    <Insurer diffgr:id="Insurer10" msdata:rowOrder="0">
    <insurer>AdfgfA</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer20" msdata:rowOrder="1">
    <insurer>AEdfgg</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer30" msdata:rowOrder="2">
    <insurer>345345</insurer>
    </Insurer>
    </Insurers>
    EOD;
    
    $pattern = '~<Insurers>(.*)</Insurers>~s';
    
    preg_match_all($pattern, $xml, $matches);
    
    print_r($matches);
    Works fine.
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  3. #3
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a reason why you don't want to use simplexml?


Bookmarks

Posting Permissions

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