Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'Employee.php';
- class TextFile extends File
- {
- private $lang;
- private $encoding;
- private $content = '';
- public function setLang($lang = 'pl')
- {
- if (!is_string($lang) || strlen($lang) > 3 || strlen($lang) < 1) {
- return false;
- }
- $this->lang = $lang;
- }
- public function setEncoding($encoding)
- {
- if (!is_string($encoding) || strlen($encoding) > 4 || strlen($encoding) < 1) {
- return false;
- }
- $this->encoding = $encoding;
- }
- public function setContent($content)
- {
- $this->content = $content;
- }
- public function countWords()
- {
- if ($this->content === '') {
- return 'Brak tekstu';
- }
- return count(explode(' ', trim($this->content)));
- }
- public function countChars()
- {
- $trimed = trim($this->content);
- $noSpaces = str_replace(' ', '', $trimed);
- return strlen($noSpaces);
- }
- public function truncate()
- {
- $this->content = '';
- }
- }
- $wmpFile = new TextFile('/asdasd', 156489789);
- $wmpFile->setEncoding('UTF-8');
- $wmpFile->setLang('pl');
- $wmpFile->setContent('Pawel bardzo lubi placki');
- echo $wmpFile->countWords();
Advertisement
Add Comment
Please, Sign In to add comment