graham23s Posted August 27, 2007 Share Posted August 27, 2007 Hey Guys, i was wondering if there was a way to count how many preg match results you get back my code is: $matchesfound = preg_match('/subject="/', $nsubject, $matchfound); any help would be great cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/ Share on other sites More sharing options...
sasa Posted August 27, 2007 Share Posted August 27, 2007 try $matchesfound = preg_match_all('/subject="/', $nsubject, $matchfound); echo $matchesfound; Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/#findComment-335602 Share on other sites More sharing options...
graham23s Posted August 27, 2007 Author Share Posted August 27, 2007 Hi Mate, it returns: 00000000000000000000000000000000000000000000000000000000000000000000 which is right if i could count the number of 0's i tried: $matchesfound = preg_match_all('/subject="/', $nsubject, $matchfound); strlen($matchesfound); } but that showed nothin. cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/#findComment-335622 Share on other sites More sharing options...
effigy Posted August 27, 2007 Share Posted August 27, 2007 It looks like you're calling preg_match_all in a loop, with each call returning 0. Is this correct? Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/#findComment-335637 Share on other sites More sharing options...
sasa Posted August 27, 2007 Share Posted August 27, 2007 i try <?php $nsubject = 'subject=" subject="+65+654subject="subject="'; $matchesfound = preg_match_all('/subject="/', $nsubject, $matchfound); echo $matchesfound; ?> and return is 4 Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/#findComment-335642 Share on other sites More sharing options...
graham23s Posted August 27, 2007 Author Share Posted August 27, 2007 yeah, its technically because im in a loop im getting back 00000000000000000000000000000000000000000000000000000000000000000000 so it should really be just 1, 0 or 1 is trhere still away to count the loop at all? cheers guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/#findComment-335687 Share on other sites More sharing options...
effigy Posted August 28, 2007 Share Posted August 28, 2007 ...create a variable that the preg_match_all results are tallied with? Quote Link to comment https://forums.phpfreaks.com/topic/66933-counting-preg-match-results/#findComment-336218 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.