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/>”;
}
}
?>
[...] you looking for word counter class, just found nice tool to count words in your articles or wherever you [...]
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
March 29, 2009 at 12:23 am
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