mysql - php - read content web page for especial address -
i want content of web page using php functions (e.g file_put_contents
, curl_init
etc.) �������
response.
why happen?
i solved problem. after content web page,i using mb_convert_encoding($body_webpage,"utf-8","gbk") , saveable in mysql whith chinese characters.
there's couple of things need in order chinese page displayed correctly.
tell php we're using utf-8 strings until end of script
mb_internal_encoding('utf-8');
tell php we'll outputting utf-8 browser
mb_http_output('utf-8');
tell bowser we'll using utf-8 charset
header('content-type: text/xml; charset=utf-8');
i've loaded page, correct character encoding, using code below:
<?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; ?>
learn more utf-8 character encoding at
Comments
Post a Comment