Question

Convert a plain Unicode text to an SMS compatible

Asked by: loggindevelop

Hello,

I'm developing a PHP application for sending SMS via a Clickatell Gateway, but my problem is I don't know how to encode the Unicode text the user writes into an SMS compatible. I mean, for example: there's a text box where you can write in whatever language you want to with any symbols and so on... When you click send, as the GSM-7 encoding hasn't got all the characters of all the languages, my application has to convert that plain text into a UTF-16 encoding so the SMS which has to be sent will arrive and look as the original written text. Anyway, I'm not sure if the proper encoding is UTF-16. I just want that the text the user types arrives to the mobile phone without changing, being the same as the written one.

Clickatell offers an online converter, but doesn't give the script for free, so I cannot use it from my PHP app. However, I leave a screenshot of the converter and the script I'm currently using.

The final result has to look like 00480065006C006C006F002C0... => (Hello, this is just a test)

<?
$user = "xxxxxx";
$password = "xxxxxx";
$api_id = "xxxxxxx";
$baseurl ="https://api.clickatell.com";
$text = urlencode("TEXT THE USER TYPES");
$to = "55555555";
$from = "logg.in";
$unicode = 1;
// auth call
$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";
// do auth call
$ret = file($url);
// split our response. return string is on first line of the data returned
$sess = split(":",$ret[0]);
if ($sess[0] == "OK") {
$sess_id = trim($sess[1]); // remove any whitespace
$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&from=$from&text=$text&unicode=$unicode";
// do sendmsg call
$ret = file($url);
$send = split(":",$ret[0]);
if ($send[0] == "ID")
echo "success
message ID: ". $send[1];
else
echo "send message failed";
} else {
echo "Authentication failure: ". $ret[0];
exit();
}
?>
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-12 at 09:00:53ID24487103
Tags

unicode

,

sms

,

unicode to sms

,

gsm

,

utf-16

,

utf-8

,

ucs2

,

ucs-2

,

ucs 2

,

utf 16

,

ut

Topics

Global System for Mobile Communications (GSM)

,

Scripting Languages

,

WebApplications

Participating Experts
2
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. send sms with asp
    hi how do i write a asp program to send sms msg to handphones? and where can i actually find those sms providers? and if possible pls include some code thank
  2. SMS
    How can i send sms to a mobile, from a pc, do i need a gsm modem? A cellular gsm phone can serve? What software do i need? Please help me. The mobile is a crosscheck GSM 1900.
  3. SMS
    I want to add the SMS feature in my website, so ppl can send sms directly to my phone from the website. Anyone know how can I achieve this in php? I registered on http://www.clickatell.com what next? Moiz

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ahoffmannPosted on 2009-06-13 at 01:18:10ID: 24618209

> The final result has to look like 00480065006C006C006F002C0 ..
this is correct
Keep in mind that this must be the binary (Unicode, aka UTF-16) representation of your data. DId you probably use that as characters?

 

by: loggindevelopPosted on 2009-06-13 at 03:13:49ID: 24618520

If I send the SMS without any encoding, as the user types it in any language (áéíóú ç ñ), as most of the characters aren't in the GSM-7 encoding, it will look like "aéiou c ñ" in the recipients mobile phone. I've been finding out how has the text to be like and found it has to be encoded into UTF-16 encoding (Unicode) looking like "00E100E900ED00F300FA002000E7002000F1" (áéíóiú´ç ñ). Now that I know in what encoding I must encode that plain text the user types, what I need is a script to do that.

I'd prefer the script in PHP.

An example of all above:

If I write "Mañana iré a la tintorería" in Spanish and send it as it is, without any encoding, I'll receive in my selfphone only the characters and symbols which are in the GSM-7 encoding (Mañana ire a la tintoreria), but that's not the proper way. Now I write the same and click on Send, then my script converts the plain text into a SMS valid UTF-16 (00E100E900ED...) so I'll receive a SMS with the same text I previously wrote (Mañana iré a la tintorería).

 

by: loggindevelopPosted on 2009-06-13 at 03:24:31ID: 24618538

In a shorter and more directly way:

I need a script to convert the plain text with any characters and symbols that a user types into a SMS valid UFT-16 encoding which looks like "00E100E900ED...". Prefered written in PHP.

Thanks!

 

by: ahoffmannPosted on 2009-06-13 at 04:52:03ID: 24618785

the browser send that encoding which was specified by the server in the HTTP response haeder and/or the pages met information in the head section and/or the form's charset attribute
If your application gets the wrong encoding, then the page used by the browser most likely did not enforce the correct encoding (that one expected by your php script).

> I need a script to convert
for now I assume that this will not be necessary, I'll wait your next comment first ...

 

by: loggindevelopPosted on 2009-06-13 at 05:48:35ID: 24618951

Hello, ahoffmann,

Thank you for you help but that's not what I need. I've been testing all what you say and more things, but it never worked fine. It only works when I use the Clickatell's converter to convert the text I type to a SMS valid Unicode that, after being finding out, I found it's UTF-16 encoding. It's a PHP page.

What I need is a PHP script that converts that text into a UTF-16 encoding, like "00E100E900ED...". The script takes the original text in a variable and converts it into a Unicode encoding (UTF-16 not UTF-8) into another variable.

Once the text has been converted I write it in the $text variable in the script I posted first and arrives perfect, but if instead of the encoded one I write the original text, when it arrives, it will only show the GSM-7 characters. Therefore I need a script to encode it, like Clickatell's one (see the picture attached above).

Thanks!

 

by: ahoffmannPosted on 2009-06-13 at 08:15:46ID: 24619508

I still assume that you miss something, anyway ...

> I need is a PHP script that converts that text into a UTF-16 encoding, like "00E100E900ED...".

Is that text in ASCII or do you get it as binary data stream?

 

by: loggindevelopPosted on 2009-06-13 at 10:34:20ID: 24620028

It's in Unicode, but not in Unicode encoding. I don't understand this very well; I mean, I don't know in what a text is, so I'm gonna explain to you as I understand. Just the plain text in any language, like Spanish, Chinese, Russian, Greek... any language which has characters and symbols that aren't inside GSM-7.

For example:

Convert Spanish signs like "áéíóú" into UTF-16 or UCS-2 (the same) that must look like  "00E100E900ED...", so that special characters will be shown in the recipient's mobile.

 

by: ahoffmannPosted on 2009-06-13 at 14:28:20ID: 24620851

I know what you mean, but you need to understand what a "language" is for humans and what it is for the computer (in particular the programs like a browser).
The same applies to the "encoding".
With "language" and "encoding" I mean those terms you used in your description.

I am aware about different characters (not languages or encoding, but literal characters as used by humans like á â à å ä). They all have their own reüresentation in Unicode and UTF-8 (which is not your question).

But you wrote about special characters "00E100E900ED..."
wher emy question is: do you mean 00E1 (and following) as binary data (Unicopde for example), or do you mean these characters as literals. As I understand your description you're talking about the literal representation of these characters.

So please make yourself used to these differences and try to explain what exactly you have and what you want (the later is Unicode in binary representation, I guess).

 

by: loggindevelopPosted on 2009-06-14 at 03:01:17ID: 24622591

OK, ahoffmann,

As I have probably been wrong all this time, or partially, I'm going to start over again without technical terms (if possible): (anyway, I know it's possible because Clickatell's converter does it, but when I asked for the script or even for help they said they couldn't give it)

I want to offer an SMS service in my Social Network which will be in many languages and internationally, so any people from anywhere will be able to use it. Therefore, as the GSM-7 doesn't have Chinese, some Spanish, or Arabic characters, for example, that text will have to be converted for when the recipient receives it to show those characters which aren't inside GSM-7. Don't ask me how or what codification or encoding, because I don't know, that's what I'm asking, how to do all that. The only thing I know is the final result MUST LOOK LIKE "00E100E900ED...", as the Clickatell's converter converts it; and after being finding out, I realized that secuence of numbers and letters is UCS-2 or UTF-16 (the same).

An example:

I'm a Chinese (or Spanish, that I'm really Spanish)  user who wants to send an SMS to his friend in Chinese via my service, but GSM-7 will show that characters as spaces or something that won't be the characters because they aren't in GSM-7, as you know. Now my script takes part, and, I don't know how, HAS TO MAKE THAT CHINESE TEXT LOOK LIKE "00E100E900ED...".  Leave apart all what I said in the first paragraphs, just take in mind the bold line above.

I hope you understand this time, and will give me the solution I need.

Thanks!

 

by: ahoffmannPosted on 2009-06-14 at 03:29:11ID: 24622700

¿do you mean you want to convert something like ñ or ë to chinese characters?
For that you need a chinese character set which has these characters, I doubt that that exist (but I don't know for sure).

> final result MUST LOOK LIKE "00E100E900ED..."
hmm, it looks like that, what is wrong?

May be this is what you want: http://us2.php.net/manual/en/function.unicode-decode.php

 

by: loggindevelopPosted on 2009-06-14 at 04:27:18ID: 24622888

No, I didn't mean that. I meant convert Chinese characters or any language which has characters that aren't inside GSM-7 to something that has to look like "00E100E900ED...".

 

by: shellgripPosted on 2009-06-25 at 07:40:28ID: 24711835

Hi loggindevelop,

I had exactly the same problem but I'm afraid it's not completely solved for me yet.  I used the scripts here:

http://hsivonen.iki.fi/php-utf8/

There's a function in the package that takes a UTF-8 encoded string and turns it into an array of Unicode decimal values.  For Clickatell you need to do a little bit of PHP to turn it into the right format for the URL string.  You have to convert the returned decimal values to hex, then pad the string to 4 characters, and build your single long string.  I did all this as follows:

foreach($uni_array as $this_val) {
        $text.=str_pad(dechex($this_val),4,"0",STR_PAD_LEFT);
}


Where $uni_array is the array returned from the utf8ToUnicode function.

This worked really well for some messages but annoyingly fails for certain word/character combinations in Russian.  I've not yet been able to solve where the problem lies but it may not happen to you so hopefully this is useful.

Jon

 

by: loggindevelopPosted on 2009-06-25 at 08:38:41ID: 24712536

Hi, shellgrip,

Really thank you for your so friendly answer! I've been trying but I couldn't make it work because I don't understand what that script exactly does, so I wonder if you could give or post your already made and working script because I need it and couldn't make it work.

Thank you!

 

by: shellgripPosted on 2009-06-25 at 08:40:31ID: 24712569

OK, there is a simple solution and this seems to work for me.  See attached code.  The returned string from this function is all ready to go into the Clickatell URL string.

Let me know if it works...

Jon

function to_utf16($text) {
	$out="";
	$text=mb_convert_encoding($text,'UTF-16','UTF-8');
	for ($i=0;$i<mb_strlen($text,'UTF-16');$i++)
		$out.= bin2hex(mb_substr($text,$i,1,'UTF-16'));
	return $out;
}

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: loggindevelopPosted on 2009-06-25 at 09:12:36ID: 24712944

It worked!!!!

Thank you, really! It's a perfect solution until we find the way to encode all the characters of all the languages.

Please, if you ever find the solution we both need, contact me at develop@logg.in.

Thanks!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...