note 54436 deleted from function.preg-match by felipe

From: Date: Sun, 23 Mar 2008 22:53:39 +0000
Subject: note 54436 deleted from function.preg-match by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137365@lists.php.net to get a copy of this message
Note Submitter: Rasqual ---- Do not forget PCRE has many compatible features with Perl. One that is often neglected is the ability to return the matches as an associative array (Perl's hash). For example, here's a code snippet that will parse a subset of the XML Schema 'duration' datatype: <?php $duration_tag = 'PT2M37.5S'; // 2 minutes and 37.5 seconds // drop the milliseconds part preg_match( '#^PT(?:(?P<minutes>\d+)M)?(?P<seconds>\d+)(?:\.\d+)?S$#', $duration_tag, $matches); print_r($matches); ?> Here is the corresponding output: Array ( [0] => PT2M37.5S [minutes] => 2 [1] => 2 [seconds] => 37 [2] => 37 )

« previous php.notes (#137365) next »