use match_all to get an array of matches.

$s = "[VET]We r NOT [PA]-Crew [TC]";

preg_match_all('/\[.*?\]/', $s, $matches);

while (list($k,$v) = each($matches[0])) {
        print "$k = $v<BR>\n";
}


prints:
0 = [VET]
1 = [PA]
2 = [TC]




> -----Original Message-----
> From: Michael Roark [mailto:[EMAIL PROTECTED]]
> Subject: [PHP] regex pattern match and extract
> 
> $sql="select nfo_gname from galaxy_nfo limit 1";
> $result=db_query($sql);
> if ($result) {
> 
> while (list($nfo_gname)=mysql_fetch_row($result)) {
> echo ("$nfo_gname");
> 
> ereg ("\[[a-zA-Z0-9]\]", $nfo_gname, $regs);
> 
> echo $regs[1];
>
> I'm trying to match any thing between [] and pull it from the string and 
> print it to the page. I want the []'s matched as well.
> 
> IE:
> 
> $nfo_gname contains the following information
> 
> [VET]We r NOT [PA]-Crew [TC]
> 
> should $regs[1] contain:
> [VET] [PA] and [TC]
> 
> ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to