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. Link to comment https://forums.phpfreaks.com/topic/110004-solved-count-how-many-times-variable-is-found-in-string/ 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 Link to comment https://forums.phpfreaks.com/topic/110004-solved-count-how-many-times-variable-is-found-in-string/#findComment-564485 Share on other sites More sharing options...
Dale_G Posted June 13, 2008 Author Share Posted June 13, 2008 Right on. Link to comment https://forums.phpfreaks.com/topic/110004-solved-count-how-many-times-variable-is-found-in-string/#findComment-564488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.