note 84991 added to function.preg-match

From: Date: Fri, 08 Aug 2008 17:45:55 +0000
Subject: note 84991 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-143314@lists.php.net to get a copy of this message
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"; ---- Server IP: 209.41.74.194 Probable Submitter: 65.220.90.98 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/84991 Del: integrated -- https://master.php.net/note/delete/84991/integrated Del: useless -- https://master.php.net/note/delete/84991/useless Del: bad code -- https://master.php.net/note/delete/84991/bad+code Del: spam -- https://master.php.net/note/delete/84991/spam Del: non-english -- https://master.php.net/note/delete/84991/non-english Del: in docs -- https://master.php.net/note/delete/84991/in+docs Del: other reasons-- https://master.php.net/note/delete/84991 Reject -- https://master.php.net/note/reject/84991 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143314) next »