PHP Curl UTF-8 Charset(PHP Curl UTF-8 字符集)
问题描述
我有一个 php 脚本,它调用另一个网页并写入页面的所有 html,一切正常,但是存在字符集问题.我的 php 文件编码是 utf-8 并且所有其他 php 文件都可以正常工作(这意味着服务器没有问题).该代码中缺少什么,所有西班牙语字母看起来都很奇怪.附注.当我将这些奇怪的字符原始版本写入php时,它们看起来都很准确.
I have an php script which calls another web page and writes all the html of the page and everything goes ok however there is a charset problem. My php file encoding is utf-8 and all other php files work ok (that means there is no problem with server). What is the missing thing in that code and all spanish letters look weird. PS. When I wrote these weird characters original versions into php, they all look accurate.
header("Content-Type: text/html; charset=utf-8");
function file_get_contents_curl($url)
{
$ch=curl_init();
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
$html=file_get_contents_curl($_GET["u"]);
$doc=new DOMDocument();
@$doc->loadHTML($html);
推荐答案
简单:当您使用 curl 时,它会将字符串编码为 utf-8
您只需要解码它们..
Simple:
When you use curl it encodes the string to utf-8
you just need to decode them..
Description
string utf8_decode ( string $data )
此函数将假定为 UTF-8
编码的数据解码为 ISO-8859-1
.
This function decodes data , assumed to be UTF-8
encoded, to ISO-8859-1
.
这篇关于PHP Curl UTF-8 字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP Curl UTF-8 字符集


基础教程推荐
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01