sanjiisan

Untitled

Apr 11th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. require 'Employee.php';
  4.  
  5. class TextFile extends File
  6. {
  7. private $lang;
  8. private $encoding;
  9. private $content = '';
  10.  
  11. public function setLang($lang = 'pl')
  12. {
  13. if (!is_string($lang) || strlen($lang) > 3 || strlen($lang) < 1) {
  14. return false;
  15. }
  16.  
  17. $this->lang = $lang;
  18. }
  19.  
  20. public function setEncoding($encoding)
  21. {
  22. if (!is_string($encoding) || strlen($encoding) > 4 || strlen($encoding) < 1) {
  23. return false;
  24. }
  25.  
  26. $this->encoding = $encoding;
  27. }
  28.  
  29. public function setContent($content)
  30. {
  31. $this->content = $content;
  32. }
  33.  
  34. public function countWords()
  35. {
  36. if ($this->content === '') {
  37. return 'Brak tekstu';
  38. }
  39.  
  40. return count(explode(' ', trim($this->content)));
  41. }
  42.  
  43. public function countChars()
  44. {
  45. $trimed = trim($this->content);
  46. $noSpaces = str_replace(' ', '', $trimed);
  47.  
  48. return strlen($noSpaces);
  49. }
  50.  
  51. public function truncate()
  52. {
  53. $this->content = '';
  54. }
  55. }
  56.  
  57.  
  58. $wmpFile = new TextFile('/asdasd', 156489789);
  59.  
  60. $wmpFile->setEncoding('UTF-8');
  61. $wmpFile->setLang('pl');
  62. $wmpFile->setContent('Pawel bardzo lubi placki');
  63.  
  64. echo $wmpFile->countWords();
Advertisement
Add Comment
Please, Sign In to add comment