note 108117 deleted from function.preg-match by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 17:38:06 +0000 |
| Subject: | note 108117 deleted from function.preg-match by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187677@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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?