diondev Posted July 29, 2009 Share Posted July 29, 2009 I can't figure this out....I'm trying to match all the elements of menu span's: <?php $menu = ' <div id="menu"> <span class="menuitem"><a href="#">Menu Item 1</a></span> <span class="menuitem"><a href="#">Menu Item 2</a></span> <span class="menuitem"><a href="#">Menu Item 3</a></span> </div> '; preg_match_all('|<span class="menuitem">(.*)</span>|i', $menu, $menu_matches); print_r($menu_matches); ?> For whatever, reason, it is only printing Menu Item 1 in the array Link to comment https://forums.phpfreaks.com/topic/167954-solved-preg_match_all-only-grabbing-first-match/ Share on other sites More sharing options...
Adam Posted July 29, 2009 Share Posted July 29, 2009 Try: preg_match_all('|<span class="menuitem">(.*?)</span>|i', $menu, $menu_matches); Edit: Actually, it works no problem for me as it is? Link to comment https://forums.phpfreaks.com/topic/167954-solved-preg_match_all-only-grabbing-first-match/#findComment-885861 Share on other sites More sharing options...
diondev Posted July 29, 2009 Author Share Posted July 29, 2009 Nevermind, apparently my brain isn't working. I was using preg_match_all on the wrong variable. Link to comment https://forums.phpfreaks.com/topic/167954-solved-preg_match_all-only-grabbing-first-match/#findComment-885886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.