0
4

1 に答える 1

0

中国語のページを正しく表示するには、いくつかの作業を行う必要があります。

スクリプトの最後まで UTF-8 文字列を使用していることを PHP に伝えます。

mb_internal_encoding('UTF-8');

UTF-8 をブラウザーに出力することを PHP に伝えます。

mb_http_output('UTF-8');

UTF-8 文字セットを使用することをクッパに伝えます

header('Content-Type: text/xml; charset=UTF-8');


以下のコードを使用して、正しい文字エンコーディングでページを正常にロードしました。

<?php
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.chinanews.com/rss/scroll-news.xml");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$pagebody=curl_exec ($ch);
curl_close ($ch);

header('Content-Type: text/xml; charset=UTF-8');
echo $pagebody;
?>

utf-8 文字エンコードの詳細については、次の URL をご覧ください。

https://phpbestpractices.org/#utf-8

于 2015-05-14T21:27:53.527 に答える