Destramic Posted August 15, 2011 Share Posted August 15, 2011 im trying to get a match on the pattern that will look like :game, :league, :whatever ...etc... but the script below will only find 1 match when there should be 2...can anyone please help? <?php $pattern = "game/:game/league/:league"; if (preg_match_all('/(?<=\w+/', $pattern, $matches)) { foreach ($matches as $match) { echo $match_count = count($matches); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244808-expression-not-working-100/ Share on other sites More sharing options...
cags Posted August 15, 2011 Share Posted August 15, 2011 Actually that matches two, you are just mis-interpreting the returned data. If you replace the foreach loop with a print_r or var_dump, you will see that $matches is actually an array that contains an array with two matches in it. The way preg_match_all works is to return an array that contains an array of all the full matches (which is $matches[0]) plus an array for every capture group in the pattern. If you actually want to see what you matched it would be... foreach ($matches[0] as $match) { echo $match; } Quote Link to comment https://forums.phpfreaks.com/topic/244808-expression-not-working-100/#findComment-1257592 Share on other sites More sharing options...
Destramic Posted August 16, 2011 Author Share Posted August 16, 2011 thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/244808-expression-not-working-100/#findComment-1257934 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.