Page 1 of 1

Assigning hits from Reg Ex to an Array: Perl to PHP

Posted: Mon Mar 30, 2009 6:48 am
by Chris K
Hi All,

I'm a PHP newbie more experienced in Perl than PHP. I want to assign the results of multiple hits from a Regex to an array and then iterate through that array and apply a function to each hit.

In Perl I would do it like:

@hits = $article =~ /\b([A-Z]{2} [0-9]{4})\b/gi;

foreach (@hits) {

my ($cleanuup_hit) = &clean_up ($_);

}

However, I can't seem to find anything similar in PHP. Does anyone know how I might be able to achieve this in PHP?

Apologies if this question has been asked before, but I have searched the posts and can't find anything.

Thanks in anticipation

Chris K

Re: Assigning hits from Reg Ex to an Array: Perl to PHP

Posted: Mon Mar 30, 2009 7:27 am
by Mark Baker
take a look at the preg_match_all() function