3

I have an application that is taking UTF8 encoded characters and needs to send them as part of xml through curl with ISO-8859-1 encoding.

This is my test code:

header('Content-Type: text/plain; charset=IS0-8859-1');

$message = '§ ° " @ # € % & / ( ) = + ` ´ ^ ¨ * - _ : . ; ,';

echo mb_convert_encoding($message, 'ISO-8859-1', 'UTF-8');

//build xml to post
$content =
    '<?xml version="1.0" encoding="ISO-8859-1"?>
    <mobilectrl_sms>
        <header>
            <customer_id>'.CUSTOMER_ID.'</customer_id>
            <password>'.PASSWORD_ID.'</password>
        </header>
        <payload>
            <sms account="'.SHORT_CODE.'">
                <message><![CDATA['.mb_convert_encoding($message, 'ISO-8859-1', 'UTF-8').']]></message>
                <to_msisdn>+12345678900</to_msisdn>
            </sms>
        </payload>
    </mobilectrl_sms>';

$posturl = MT_URL;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml", "Content-length: ".strlen($content), "charset=ISO-8859-1"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);

In the browser it almost works, I see § ° " @ # ? % & / ( ) = + ` ´ ^ ¨ * - _ : . ; ,

notice the Euro Sign €

But when it comes through as a text message I am seeing § ? " @ # ? % & / ( ) = + ? ? ^ ? * - _ : . ; ,

I can't figure it out, I've tried utf8_decode also but that seems to make it worse. Am I missing something?

Thanks

3 Answers 3

4

There is no euro sign in ISO-8859-1, so it gets substituted with a question mark. There's nothing you can do about it, except choosing something else to substitute it with.

The same goes for the other characters that get converted to ?s.

Sign up to request clarification or add additional context in comments.

2 Comments

This is why ISO-8859-* is considered legacy and UTF-8/16 are considered to be the sensible and modern choices among the available standards.
Thanks for the answer, I'll have to look at converting those characters to something close. Its for a sms application and apparently a lot of the carriers gsm still uses iso-8859 and this is in Europe! I guess no one can text the Euro sign.
4

AFAIK, the multibyte extension doesn't know how to transliterate characters such as the Euro symbol, but iconv() does (example code from http://php.net/function.iconv#example-2228):

<?php
$text = "This is the Euro symbol '€'.";

echo 'Original : ', $text, PHP_EOL;
echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
echo 'IGNORE   : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
echo 'Plain    : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;

The above example will output something similar to:

Original : This is the Euro symbol '€'.
TRANSLIT : This is the Euro symbol 'EUR'.
IGNORE   : This is the Euro symbol ''.
Plain    :
Notice: iconv(): Detected an illegal character in input string in .\iconv-example.php on line 7
This is the Euro symbol '

Note the use of iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text) which transliterates the '€' character into its Latin-1 "equivalent" of 'EUR'.

Comments

2

Some SMS protocols accepts "%80" for the Euro sign. So you could try substituting the "€" with "%80" and URL-encode the rest of the string using ISO-8859-1. It worked for me for some SMS protocols.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.