![]() |
Count words in Div - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Count words in Div (/showthread.php?tid=48509) |
Count words in Div - El Forum - 01-19-2012 [eluser]Perkin5[/eluser] How would I set about counting words in a div? Counting words in a string is straightforward but how do I make the string equal the contents of the div? Count words in Div - El Forum - 01-19-2012 [eluser]John_Betong_002[/eluser] What is the source for the div contents? Can you give an example? Count words in Div - El Forum - 01-19-2012 [eluser]PhilTem[/eluser] Hm... I'd suggest using Code: preg_match_all($pattern, $div_string, $matches); with the correct pattern that also matches some attributes like 'class' or 'id' within '<div>' if you have these (I'm not good at regexp-patterns, better ask somebody else ![]() Code: count($matches); to count the amount of matched items i.e. words. But what exactly is your definition for 'word'? Is it a random string pattern surrounded by white-spaces? Or must it be a word that can be found within a dictionary? So to speak: 'Real words' or only 'character combinations surrounded by white-spaces'? What's your use case? Count words in Div - El Forum - 01-19-2012 [eluser]Perkin5[/eluser] My div would be like this: Code: <div id="somediv"> where $wordcount is a function that counts the words in the div. I'm aware of things like: Code: function wordcount($str) { but how do I make $str equal to the div contents? Count words in Div - El Forum - 01-19-2012 [eluser]John_Betong_002[/eluser] I fail to understand how the string of words get into the DIV. Code: <?php Count words in Div - El Forum - 01-19-2012 [eluser]Perkin5[/eluser] OK, now it is confirmed...I am definitely stupid! Thank you very much for leading the challenged. I had visions of something like $str = $css_str("#somediv"); etc etc...sad. Count words in Div - El Forum - 01-23-2012 [eluser]John_Betong_002[/eluser] No problem we all have our off-days ![]() My ongoing problem is to try and wrap my head around global time zones for forum posts, emails, FaceBook, Google Webmaster Tools... the bl@@dy list gets longer every day ![]() Count words in Div - El Forum - 01-23-2012 [eluser]Perkin5[/eluser] And they say time is the great healer! |