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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Chris K
Forum Newbie
Posts: 1
Joined: Mon Mar 30, 2009 6:37 am

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

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post by Mark Baker »

take a look at the preg_match_all() function
Post Reply