I like PHP a lot
5
<?php
class WordCounter{
private $text;
function __construct($t){ $this->text=$t; }
function count(){
$t=trim($this->text);
if($t==='') return 0;
$tokens=preg_split('/\\s+/', $t);
return count($tokens);
}
}
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$wc=new WordCounter($inputText);
echo $wc->count();
?>
<?php
class WordCounter{
private $text;
function __construct($t){ $this->text=$t; }
function count(){
$t=trim($this->text);
if($t==='') return 0;
$tokens=preg_split('/\\s+/', $t);
return count($tokens);
}
}
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$wc=new WordCounter($inputText);
echo $wc->count();
?>