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