bouwob Posted February 23, 2007 Share Posted February 23, 2007 if (preg_match('/([a-zA-Z]+DM)/', $pieces[3], $matches)) { foreach($matches as $match) { $dm = $dm.$match.","; echo $dm; } } B-series, 00, B18C5, Integra Type R USDM this is the data that comes in. but the variable prints out "USDM,USDM" when it should print out only 1. There could be more than 1 match though. such as B-series, 00, B18C5, Integra Type R JDM USDM EDM and that should make $dm = "JDM,USDM,EDM" any ideas tia Quote Link to comment Share on other sites More sharing options...
effigy Posted February 23, 2007 Share Posted February 23, 2007 ...the variable prints out "USDM,USDM" when it should print out only 1. Per the documentation: If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on. There could be more than 1 match though...and that should make $dm = "JDM,USDM,EDM" Also from the docs: preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.