Re: preg_match
| From: | Alexey Shein | Date: | Fri, 08 Jul 2011 14:11:38 +0000 |
| Subject: | Re: preg_match | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53784@lists.php.net to get a copy of this message | ||
2011/7/8 Rafael Dohms <listas@rafaeldohms.com.br>:
> Still, this is preg_match it only returns one match, why should i get
> a array and have to use ugly things like $matches[0] afterwards?
> It just makes for very ugly syntax and extra code, a simple function
> would make this cleaner and more intuitive, first time using
> preg_match is a nightmare.
>
You forget about subpatterns, so array can contain more than 1 value:
php > preg_match('/p(hp)/', 'php', $matches); var_dump($matches);
array(2) {
[0]=>
string(3) "php"
[1]=>
string(2) "hp"
}
> --
> Rafael Dohms
> PHP Evangelist and Community Leader
> http://www.rafaeldohms.com.br
> http://www.phpsp.org.br
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Regards,
Shein Alexey