gpt4 book ai didi

php - mysql删除了文本的字符编码

转载 作者:行者123 更新时间:2023-11-30 22:37:30 26 4
gpt4 key购买 nike

当我在浏览器上运行它并回显文本时,我必须遵循运行良好的代码,它显示正确的阿拉伯字符,但问题是当我将它保存到 mysql 数据库中时,一切都开始像在下面的截图。 enter image description here

这里是数据库上设置的字符编码enter image description here

最后是我的代码。我现在对如何解决所有这些问题感到非常困惑和沮丧,到目前为止我还没有找到任何解决方案。

header('Content-Type: text/html; charset= Windows-1256');

require 'vendor/autoload.php';

use Goutte\Client;

$client = new Client();

$lebanonfiles = $client->request('GET', 'http://www.lebanonfiles.com');

$news_container = $lebanonfiles->filter('#mcs4_container .line');


$news_container->each(function($node) {

$temp = explode(' ',trim($node->text()));


$db = new MysqliDb (Array (
'host' => 'localhost',
'username' => 'root',
'password' => 'rolemodel',
'db'=> 'wade3',
'charset' => 'utf8_general_ci'));


$temp_time = date('Y-m-d H:i:s', strtotime($temp[0]));

$temp_text = utf8_decode(str_replace($temp[0]," ",$node->text()));

$temp_url = "http://www.lebanonfiles.com";

$data = Array(
'updated' => $temp_time,
'scraped_on' => $temp_time,
'link' =>$temp_url,
'title'=> $temp_text,
'feedsource' => 'lebanonfiles'
);

$db->insert('news', $data );

});

最佳答案

将字符集更改为

'charset' => 'cp1256'

因为客户端编码必须匹配数据的实际编码,如 http header 所建议的那样是 windows-1256。

删除行

$temp_text = utf8_decode(str_replace($temp[0]," ",$node->text()));

因为您的数据中没有可解码的 utf。

关于php - mysql删除了文本的字符编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32072037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com