Skip to content

Commit

Permalink
Fix the message coding detection
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Leroux <ludovic.leroux@corp.ovh.com>
  • Loading branch information
Ludovic Leroux committed Jul 13, 2016
1 parent 5329460 commit 96fb259
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function send($message)
}

// Manage coding
$coding = (max(array_map('ord', str_split($message))) > 127) ? '8bit' : '7bit';
$coding = ($this->is_gsm0338($message) ? '7bit' : '8bit');

// Prepare request parameters
$parameters = (object) array('message' => $message, 'receivers' => $this->receivers, 'noStopClause' => !$this->isMarketing, 'differedPeriod' => $differedPeriod, 'coding' => $coding, 'tag' => $this->tag);
Expand Down Expand Up @@ -225,4 +225,36 @@ public function setSender($sender)

$this->sender = $sender;
}

private function is_gsm0338($utf8_string) {

$gsm0338 = array(
'@','Δ',' ','0','¡','P','¿','p',
'£','_','!','1','A','Q','a','q',
'$','Φ','"','2','B','R','b','r',
'¥','Γ','#','3','C','S','c','s',
'è','Λ','¤','4','D','T','d','t',
'é','Ω','%','5','E','U','e','u',
'ù','Π','&','6','F','V','f','v',
'ì','Ψ','\'','7','G','W','g','w',
'ò','Σ','(','8','H','X','h','x',
'Ç','Θ',')','9','I','Y','i','y',
"\n",'Ξ','*',':','J','Z','j','z',
'Ø',"\x1B",'+',';','K','Ä','k','ä',
'ø','Æ',',','<','L','Ö','l','ö',
"\r",'æ','-','=','M','Ñ','m','ñ',
'Å','ß','.','>','N','Ü','n','ü',
'å','É','/','?','O','§','o','à'
);

$len = mb_strlen($utf8_string, 'UTF-8');

for( $i=0; $i < $len; $i++) {
if (!in_array(mb_substr($utf8_string,$i,1,'UTF-8'), $gsm0338)) {
return false;
}
}

return true;
}
}

0 comments on commit 96fb259

Please sign in to comment.