Re: asterix for arrray_search?

From: Date: Mon, 20 Jun 2005 16:43:27 +0000
Subject: Re: asterix for arrray_search?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-217230@lists.php.net to get a copy of this message
Richard Lynch wrote:
On Sat, June 18, 2005 10:11 am, Merlin said: ...
I believe that in recent versions of PHP, the preg_* functions will accept an array as an argument... Or maybe I dreamed that.
FYI I thought this also... but it appears that you can only do one match at a time with preg_match(). The only one I found that allows the array syntax that you're referring to above is preg_replace(). All the same you can still set up an array full of regex patterns, loop through each of these, and do whatever you want with those matches. <?php $regs = array(
          '/match this text/',
          '/match this/',
          '/match/'
        );
$text = "Why don't you run this code and see if you can match this example?";
$matches = array(); foreach($regs as $regex) { preg_match($regex, $text, $matches[]); } print_r($matches); ?> -- NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-general&w=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php

« previous php.general (#217230) next »