Example #1
0
<?php

class WordCounter
{
    const ASC = 1;
    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/>";
        }
    }
}
$wc = new WordCounter("words.txt");
$wc->count(WordCounter::DESC);
Example #2
0
include_once 'class.statictester.php';
include_once 'class.student.php';
include_once 'class.overloader.php';
/*----------  Extended Emailer  ----------*/
$emailerobject = new ExtendedEmailer();
$emailerobject->setSender('*****@*****.**');
$emailerobject->addRecipients('*****@*****.**');
$emailerobject->setSubject('Just a Test');
$emailerobject->setBody('Content of Email');
$emailerobject->sendEmail();
/*----------  Factorial  ----------*/
$factorial = new Factorial(5);
$factorial->showResult();
/*----------  WordCounter  ----------*/
$count = new WordCounter('words.txt');
$count->count(WordCounter::ASC);
/*----------  HTML Emailer  ----------*/
$newemailerobject = new HtmlEmailer('wdarking');
$newemailerobject->addRecipients('*****@*****.**');
$newemailerobject->setSubject('*****@*****.**');
$newemailerobject->setBody('Hi there :D');
$newemailerobject->sendEmail();
$newemailerobject->sendHtmlEmail();
/*----------  DBDriver  ----------*/
$dbdriver = DBManager::getMySQLDriver();
/*----------  Static Tester  ----------*/
$tester = new StaticTester();
print "<br>";
StaticTester::checkIdFromStaticMethod();
print "<br>";
$tester2 = new StaticTester();