fork download
  1. <?php
  2.  
  3. class StringBuilder
  4. {
  5.  
  6. protected $string;
  7.  
  8. public function __construct()
  9. {
  10. $this->string = "";
  11. }
  12.  
  13. public function set($str)
  14. {
  15. if (mb_detect_encoding($str) != "UTF-8") {
  16. $this->string = iconv(mb_detect_encoding($str), "UTF-8", $str);
  17. } else {
  18. $this->string = $str;
  19. }
  20. }
  21.  
  22. public function changeEncod($enc)
  23. {
  24. $this->string = iconv(mb_detect_encoding($str), $enc, $str);
  25. }
  26.  
  27. public function getLength()
  28. {
  29. return mb_strlen($this->string);
  30. }
  31.  
  32. public function chatAt($c)
  33. {
  34. return mb_substr($this->string, $c, 1);
  35. }
  36.  
  37. public function concat($param)
  38. {
  39. $this->string += $param;
  40. }
  41.  
  42. public function __toString()
  43. {
  44. return $this->string;
  45. }
  46.  
  47. }
  48.  
  49. $str = new StringBuilder();
  50. $str->set("строка");
  51. $str->changeEncod("ASCII");
  52. if (mb_detect_encoding($str) != "UTF-8") {
  53. echo "не ютф";
  54. }
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
��