note 54436 added to function.preg-match

From: Date: Mon, 04 Jul 2005 16:03:29 +0000
Subject: note 54436 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-91429@lists.php.net to get a copy of this message
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 ) ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54436 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54436&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54436&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54436&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54436&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54436&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54436&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54436&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91429) next »