Boolean Island !

Word Counter By PHP

Posted by: ranacse05 on: May 6, 2008

I was reading Hasin Bhai’s New book Object Oriented Programming with PHP5.In chapter 2 i got a nice example of OOP.Its a word counter.Its a nice tool actually and pretty little too.Here is that example. :)

<?
class WordCounter
{
const ASC=1;  //you need not use $ sign before Constants
const DESC=2;
private $words;
function __construct($filename)
{
$file_content = file_get_contents($filename);
$this->words =
(array_count_values(str_word_count(strtolower
($file_content),1)));
}
public function count($order)
{
if ($order==self::ASC)
asort($this->words);
else if($order==self::DESC)
arsort($this->words);
foreach ($this->words as $key=>$val)
echo $key .” = “. $val.”<br/>”;
}
}
?>

4 Responses to "Word Counter By PHP"

[...] you looking for word counter class, just found nice tool to count words in your articles or wherever you  [...]

Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language ;)
See you!
Your, Raiul Baztepo

Hello !!! ^_^
I am Piter Kokoniz. Just want to tell, that your posts are really interesting
And want to ask you: what was the reasson for you to start this blog?
Sorry for my bad english:)
Thank you:)
Your Piter Kokoniz, from Latvia

Thanks for ur comment .
When i stuck i found solution on the blog . So then i wanna share those solution through my blog. Got it ?

Leave a Reply

My blog worth


My site is worth $3431.
How much is yours worth?

My Twittes

FireFox

Firefox 3

My Facebook

this is Raquibul's profile

View Raquibul Islam's profile on LinkedIn

My fav

 

May 2008
S M T W T F S
« Apr   Jun »
 123
45678910
11121314151617
18192021222324
25262728293031

Flickr Photos

Moon !

Moon !

Leevio

Leevio

Leevio

Tea !

History

me

More Photos

My Bookmarks

Dynamic Malloc

Blog Stats

  • 46,705 hits