I know this is a port mania today but i finally solved a problem that has been bugging me for a few days now. I wanted to send an sms via Clicaktell’s gateway that i wanted it to be utf. This gateway supports this kind of messages but with a trick.
When you set the UTF support on your message, your message needs to be UTF-16 url encoded. This is tricky. For instance the folloring will not work.
urlencode(mb_convert_encoding($text, 'UTF-16', 'UTF-8'))
With this you will get an error message saying that your utf data are not right. Please notice that i used mb_convert_encoding from the mbstring module in php (more about the mbstring module in php’s manual here). So here is a function i found on php.net’s manual and i modified a little bit to use.
function utf16urlencode($str)
{
$str = mb_convert_encoding($str, 'UTF-16', 'UTF-8');
$out = '';
for ($i = 0; $i < mb_strlen($str, 'UTF-16'); $i++)
{
$out .= bin2hex(mb_substr($str, $i, 1, 'UTF-16'));
}
return $out;
}
Using the function above you can convert your string to add it in the url of the message sending. Hope this helps!
THANKS MAN 🙂
Great code! Not perfect in all cases, but still it’s by far the best I’ve found.
@Sjarel: thanks for commenting… it could be better indeed but still it does what it is intended to do 🙂
To be more precise, I hope it can be helpful : When I try to send ‘Družstevník’ with this function, I receive ‘Drustevník’ on my mobile. So it does the job indeed, but one character was lost.
hm… well it seems that that ž can’t be converted to UTF-16 or something. it must be that… sorry i can’t help you more but i am not aware of the language and how characters stored and converted…
No problem, just wanted to let you know …