Regular Expression Problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi List

I must be dumb as I have been battling my way through regular expression
examples for a while and I can not work out why the following does not work
properly. I am the first to admit that regular expressions confuse me greatly.

The string is a piece of XML as follows and I have put that string into a
variable called $xml_string


<flights>
         <flight flightId="19417361" addAdtPrice="0.0" addChdPrice="0.0" addInfPrice="0.0">
                 <legXRefs>
                           <legXRef legId="23862812" class="V"></legXRef>
                           <legXRef legId="23862813" class="V"></legXRef>
                 </legXRefs>
         </flight>
         <flight flightId="19417360" addAdtPrice="0.0" addChdPrice="0.0" addInfPrice="0.0">
                 <legXRefs>
                           <legXRef legId="23862810" class="V"></legXRef>
                           <legXRef legId="23862811" class="V"></legXRef>
                 </legXRefs>
         </flight>
</flights>


What I am trying to do is extract the first <flight ..... /flight> chunk.

I am using the following, based on the example at
http://php.net/manual/en/function.preg-match.php example 3

preg_match('#<flight .*\/flight>#', $xml_string,$matches);
$tempstr = $matches[0];

What I actually get in $tempstr is everything from the first <flight through to
the last (second) </flight>

I would have expected preg_match to have matched from the first <flight through
to the first </flight>.

I suspect I do not have the regular expression correct. I would great appreciate
any help on sorting out the regular expression so that it only returns the first
chunk of the string.



Regards,
Richard Luckhurst

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux