HelperModel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. /**
  6. * ContactForm is the model behind the contact form.
  7. */
  8. class HelperModel extends Model
  9. {
  10. public static function stripWhitespaces($string)
  11. {
  12. $old_string = $string;
  13. $string = strip_tags($string);
  14. $string = preg_replace('/([^\pL\pN\pP\pS\pZ])|([\xC2\xA0])/u', ' ', $string);
  15. $string = str_replace(' ',' ', $string);
  16. $string = trim($string);
  17. if ($string === $old_string) {
  18. return $string;
  19. } else {
  20. return self::stripWhitespaces($string);
  21. }
  22. }
  23. public static function clearSectionString($string,$mask)
  24. {
  25. $result = '';
  26. for ($i=0;$i < mb_strlen($string); $i++) {
  27. $lit = mb_substr($string, $i, 1, 'UTF-8');
  28. foreach ( $mask as $l) {
  29. //var_dump($lit .'==='. $l);
  30. if ( $lit === $l) {
  31. $result .= $lit;
  32. }
  33. }
  34. }
  35. $result = mb_strtoupper($result);
  36. return $result;
  37. }
  38. }