In php how to display chinese character?

蓝咒 提交于 2019-12-12 05:15:00

问题


what I build now is I grabbing from RSS feed in chinese RSS website, but once I echo out is blank, my code was work on english RSS, I try a lot of decode,iconv, header("Content-Type: text/html; charset=utf-8");, but still the same cannot display any chinese word on my screen.

here is my coding:

header("Content-Type: text/html; charset=utf-8");
function getrssfeed($feed_url){    
$Current = date("Y-m-d" ,strtotime("now"));
$content = file_get_contents($feed_url);    
$xml = new SimpleXmlElement($content);
$body = "";
    foreach($xml->channel->item as $entry){     
        $body .= get_html_translation_table(htmlspecialchars_decode(strip_tags($Current ." ". $entry->description))) . "\n\n";      
        //$result = iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $body);
        $i++;       
        if($i==5) {
            break;      
        }       
    }
echo $body;
}

getrssFeed("http://news.baidu.com/n?cmd=1&class=enternews&tn=rss");

Can you guy help me how to solve my problem ?

thank you


回答1:


in your HTML header put this

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta>



回答2:


Two things you need to do

  1. Set document type or header as

content="text/html;charset=utf-8"

  1. Save those user Chinese characters in database with field collation as utf8_general_ci



回答3:


may be you can use this function with

mb_convert_encoding

,but at the same time ,you should attention the native document charset must be utf-8 or gb2312



来源:https://stackoverflow.com/questions/7479668/in-php-how-to-display-chinese-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!