You are here: Re: [PHP] asterix for arrray_search? « PHP « IT news, forums, messages
Re: [PHP] asterix for arrray_search?

Posted by Jason Barnett on 06/20/05 19:43

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация