jimmyt1988 Posted August 3, 2009 Share Posted August 3, 2009 How do I count how many times a string has been used within another larger string: $str = ' <!--Start of section!--> <h2> <div id="newscontent"> <div id="newsheader"> <a href = "newsPages/basingstokeBalloonFiesta.html">Basingstoke Balloon Fiesta 2009</a> </div> <div id = "contentContainer"> <div id="newsContentLeft"> <a href = "newsPages/basingstokeBalloonFiesta.html"><img src="images/newsImages/basingstokeBalloonFiestaS.jpg" alt="Flight video over London - 16th June" width = "100" height = "100" /></a> </div> <div id="newsContentRight"> <TABLE class = "left" width="398px" height="100px"> <TR> <TD valign = "center"> The Basingstoke balloon festival got off to a flying start this morning with a dozen balloons taking off at the press launch for the event.. </TD> </TR> </TABLE> </div> </div> <div id="newsfooter"> <div id="newsdate"> 31/07/2009 </div> </div> </div> </h2> <!--End of section!--> '; echo $str; $search = "<!--Start of section!-->"; $amount = str_word_count($search, $str); echo $amount; I want $amount to return 1 because "<!--Start of section!-->" only occurs once within the $str. Link to comment https://forums.phpfreaks.com/topic/168624-word-count-within-a-string/ Share on other sites More sharing options...
Mark Baker Posted August 3, 2009 Share Posted August 3, 2009 substr_count() Link to comment https://forums.phpfreaks.com/topic/168624-word-count-within-a-string/#findComment-889506 Share on other sites More sharing options...
jimmyt1988 Posted August 3, 2009 Author Share Posted August 3, 2009 Ah thanks so much, got it to work coz of that! Link to comment https://forums.phpfreaks.com/topic/168624-word-count-within-a-string/#findComment-889508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.