Skip to content
May 6, 2008 / ranacse05

Word Counter By PHP

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 =
public function count($order)
if ($order==self::ASC)
else if($order==self::DESC)
foreach ($this->words as $key=>$val)
echo $key .” = “. $val.”<br/>”;



Leave a Comment
  1. RaiulBaztepo / Mar 29 2009 12:23 am

    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

  2. PiterKokoniz / Apr 8 2009 12:10 am

    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

    • ranacse05 / Apr 8 2009 5:06 pm

      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 ?


  1. Word counter class | PHP Readings

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: