Dale_G Posted June 13, 2008 Share Posted June 13, 2008 Hey everyone, I need to know how to output, as an integer, the number of times some data is found in a string. For example $data = 'two'; $string = 'oneonethreetwofourseventwoeightninetwotwelve'; 'two' is found three times in $string, I'd like to output '3', in integer form. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 13, 2008 Share Posted June 13, 2008 You probably want to use the function substr_count() <?php $data = 'two'; $string = 'oneonethreetwofourseventwoeightninetwotwelve'; echo substr_count($string,$data) . "<br>"; ?> Ken Quote Link to comment Share on other sites More sharing options...
Dale_G Posted June 13, 2008 Author Share Posted June 13, 2008 Right on. 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.