我有一个使用 UTF8 编码字符的应用程序,需要通过 curl 使用 ISO-8859-1 编码将它们作为 xml 的一部分发送。
这是我的测试代码:
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);
在浏览器中它几乎可以工作,我看到 § °" @ # ? % & / ( ) = + ` ´ ^ ¨ * - _ : . ; ,
注意欧元符号€</p>
但是当它以短信的形式出现时,我看到的是 § ? " @ # ? % & / ( ) = + ? ? ^ ? * - _ : . ; ,
我想不通,我也尝试过 utf8_decode ,但这似乎使情况变得更糟。我错过了什么吗?
谢谢