note 84991 deleted from function.preg-match by bjori
| From: | bjori@php.net | Date: | Sat, 09 Aug 2008 17:17:05 +0000 |
| Subject: | note 84991 deleted from function.preg-match by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143328@lists.php.net to get a copy of this message | ||
Note Submitter: mike at debitage.com
Reason: bad code
----
the following will grab the value within xml tags
<?php
function get_tag( $tag, $xml ) {
$tag = preg_quote($tag);
preg_match_all('{<'.$tag.'[^>]*>(.*?)</'.$tag.'>}',
$xml, $matches, PREG_PATTERN_ORDER );
return $matches[1];
}
?>
USE:
$xml = "<CancelledDate>8/5/2008 5:23:30 PM</Cancelled
Date><CancelledReason>Cancelled due to
error in order</CancelledReason>
<ShipDate>8/5/2008</ShipDate><FreightAmount>
50.0000</FreightAmount>";
$cancelDate = get_tag( "CancelledDate", $xml );
returns:
$cancelDate[0] = "8/5/2008 5:23:30 PM";