Why does php return garbled characters?
The following are the returned results:
<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>
The following is the code, I also wrote the code, why is it still garbled?:
<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>
Reply content:
The following are the returned results:
<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>
The following is the code, I also wrote the code, why is it still garbled?:
<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>
Finally change it to return iconv('gbk', 'UTF-8', $output);
It will be ok. The key is the original webpage of GBK
<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>
Original site is gbk

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
