3

UTF8 でエンコードされた文字を使用するアプリケーションがあり、それらを ISO-8859-1 エンコーディングで curl を介して 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も試しましたが、それはそれを悪化させるようです. 何か不足していますか?

ありがとう

4

3 に答える 3

4

私の知る限り、マルチバイト拡張機能はユーロ記号などの文字を音訳する方法を知りませんが、そうします ( http://php.net/function.iconv#example-2228iconv()のコード例):

<?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;

上記の例では、次のようなものが出力されます。

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 '

iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text)which を使用すると、'€' 文字が Latin-1 の「同等の」'EUR' に音訳されることに注意してください。

于 2011-03-29T15:47:53.173 に答える
3

ISO-8859-1にはユーロ記号がないため、疑問符に置き換えられます。それを置き換えるために何か他のものを選ぶことを除いて、あなたがそれについてできることは何もありません。

sに変換される他の文字についても同じことが言え?ます。

于 2011-03-29T15:43:56.813 に答える
1

一部の SMS プロトコルは、ユーロ記号として「%80」を受け入れます。したがって、「€」を「%80」に置き換えて、残りの文字列を ISO-8859-1 を使用して URL エンコードすることができます。一部の SMS プロトコルではうまくいきました。

于 2011-06-20T12:37:35.090 に答える