kratsg Posted November 7, 2007 Share Posted November 7, 2007 Is it just me, or does the topic of $matches always seem to bug me a little bit? IE: how the array for $matches is compiled, exactly what goes in what for different situations, etc... For me, I'm always a little irked with this guy, like I can never remember EXACTLY what $matches[0][0] would be, etc... Does anyone have a simple way of comprehending this (and don't refer to the php manual, cause that thing just seems to make it more complex than it actually is). Quote Link to comment https://forums.phpfreaks.com/topic/76320-solved-preg_match-preg_match_all-and-matches/ Share on other sites More sharing options...
btherl Posted November 7, 2007 Share Posted November 7, 2007 Element 0 is always the full pattern matches, and elements 1 and up are the individual matches. That's all there is to preg_match() For preg_match_all(), it depends on whether you set PREG_PATTERN_ORDER or PREG_SET_ORDER. Thay may lead to some confusion.. Basically PREG_PATTERN_ORDER means element 0 is an array of all the full pattern matches, and elements 1 and up are arrays of individual matches. Try var_dump() on an example and it'll make sense. PREG_SET_ORDER is the other option.. you basically get an array of the arrays you WOULD have gotten if you'd run preg_match() lots of times. Just imagine you kept running preg_match() and put all the results into a big array. That's PREG_SET_ORDER. preg_match_all('|(a)(b)|', 'ababab', &$matches); # Default to PREG_PATTERN_ORDER var_dump($matches); preg_match_all('|(a)(b)|', 'ababab', &$matches, PREG_SET_ORDER); var_dump($matches); Quote Link to comment https://forums.phpfreaks.com/topic/76320-solved-preg_match-preg_match_all-and-matches/#findComment-386453 Share on other sites More sharing options...
kratsg Posted November 7, 2007 Author Share Posted November 7, 2007 So, what the heck is considered a 'full pattern' match, the whole string, or the part of the string that matches the whole pattern? Quote Link to comment https://forums.phpfreaks.com/topic/76320-solved-preg_match-preg_match_all-and-matches/#findComment-386646 Share on other sites More sharing options...
effigy Posted November 7, 2007 Share Posted November 7, 2007 So, what the heck is considered a 'full pattern' match, the whole string, or the part of the string that matches the whole pattern? Quote Link to comment https://forums.phpfreaks.com/topic/76320-solved-preg_match-preg_match_all-and-matches/#findComment-386788 Share on other sites More sharing options...
kratsg Posted November 8, 2007 Author Share Posted November 8, 2007 Nice, I think I got it (although I'll probably forget it after a month *jots this down on the post-it by the computer*) :-o Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/76320-solved-preg_match-preg_match_all-and-matches/#findComment-387243 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.