note 108117 added to function.preg-match

From: Date: Fri, 30 Mar 2012 01:15:00 +0000
Subject: note 108117 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-186908@lists.php.net to get a copy of this message
In response to "kevin 08-Jan-2012 06:11". Eval is dangerous and your comparison text better be sanitized before you even consider running it. PCRE Syntax allows for named groups, which will yield associative results. For instance <?php $str = "something"; $expr = "/some(?P<capturedname>[a-z]+)/"; $results = array(); preg_match($expr, $str, $results); var_dump($results); ?> You'll get a result set like this: [0] => 'something'; // this is the entire string contents that matched [1] => 'thing'; // this is what the subgroup 1 found [capturedname] => 'thing'; // this is what the named subgroup found. [capturedname] = 'thing'; // notice the matched index? ---- Server IP: 92.48.119.85 Probable Submitter: 69.180.132.181 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/108117 Del: integrated -- https://master.php.net/note/delete/108117/integrated Del: useless -- https://master.php.net/note/delete/108117/useless Del: bad code -- https://master.php.net/note/delete/108117/bad+code Del: spam -- https://master.php.net/note/delete/108117/spam Del: non-english -- https://master.php.net/note/delete/108117/non-english Del: in docs -- https://master.php.net/note/delete/108117/in+docs Del: other reasons-- https://master.php.net/note/delete/108117 Reject -- https://master.php.net/note/reject/108117 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186908) next »