filtersms

filtersms
SYNOPSIS

filtersms($s)

CODE
  1. function filtersms($s) {
  2.     $charset7bit = "@£\$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà";
  3.     $charset7bitext = "\f^{}\\[~]|€";
  4.  
  5.     $s = preg_replace('/\R/', "\r\n", trimsms($s));
  6.  
  7.     if (preg_match('/[^' . preg_quote($charset7bit . $charset7bitext, '/') . ']/', $s)) {
  8.         $coding='16bit';
  9.         $maxlen=70;
  10.         $extlen=67;
  11.     }
  12.     else {
  13.         $coding='7bit';
  14.         $maxlen=160;
  15.         $extlen=153;
  16.  
  17.         $s = preg_replace('/([' . preg_quote($charset7bitext, '/') . '])/u', "\e\\1", $s);
  18.     }
  19.  
  20.     $msglen = mb_strlen($s, 'UTF-8');
  21.  
  22.     if ($msglen > $maxlen) {
  23.         $count = 1 + floor($msglen / $extlen);
  24.         $len = $count * $extlen;
  25.     }
  26.     else {
  27.         $count = 1;
  28.         $len = $maxlen;
  29.     }
  30.  
  31.     return array($s, $coding, $msglen, $count, $len);
  32. }
  33.  
  34. function trimsms($s) {
  35.     return preg_replace('/ *(\R)+/', '\1', preg_replace('/^ /m', '', preg_replace('/[ \t]+/', ' ', trim($s))));
  36. }
SEE ALSO

normsms

Comments

To add a comment, click here.