以下是返回结果:
<code>var hq_str_sh601006="������·,6.360,6.350,6.330,6.390,6.320,6.320,6.330,25996996,165270113.000,1055700,6.320,412700,6.310,524900,6.300,116900,6.290,131500,6.280,93700,6.330,340020,6.340,728100,6.350,668100,6.360,928814,6.370,2016-08-26,15:00:00,00"; </code>
以下是代码,也写了个编码了,怎么还是乱码呢?:
<code><head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>PHP实验-3</title>
</head>
<?php
$url = "http://hq.sinajs.cn/list=sh601006";
$info = getCurlData($url);
echo $info . "</br>" ;
function getCurlData($url)
{
if (empty ( $url ))
{
return false;
}
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
$output = curl_exec ( $ch );
curl_close ( $ch );
return $output;
}</code>以下是返回结果:
<code>var hq_str_sh601006="������·,6.360,6.350,6.330,6.390,6.320,6.320,6.330,25996996,165270113.000,1055700,6.320,412700,6.310,524900,6.300,116900,6.290,131500,6.280,93700,6.330,340020,6.340,728100,6.350,668100,6.360,928814,6.370,2016-08-26,15:00:00,00"; </code>
以下是代码,也写了个编码了,怎么还是乱码呢?:
<code><head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>PHP实验-3</title>
</head>
<?php
$url = "http://hq.sinajs.cn/list=sh601006";
$info = getCurlData($url);
echo $info . "</br>" ;
function getCurlData($url)
{
if (empty ( $url ))
{
return false;
}
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
$output = curl_exec ( $ch );
curl_close ( $ch );
return $output;
}</code>
最后改成 return iconv('gbk', 'UTF-8', $output);就ok了吧 关键原来的是GBK的网页
立即学习“PHP免费学习笔记(深入)”;
<code>~ ᐅ curl -I http://hq.sinajs.cn/list\=sh601006 HTTP/1.1 200 OK Cache-Control: no-cache Content-Length: 250 Connection: Keep-Alive Content-Type: application/x-javascript; charset=GBK</code>
原站是gbk
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号