php - RSS 编码问题
问题描述
我正在开发优惠网站,我正在从 RSS 获得优惠。
<?php
set_time_limit(0);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$rss_url = 'https://grabo.bg/rss/exportxml/stolicabg/?affid=50781';
$xml = simplexml_load_file($rss_url);
foreach($xml->deal as $item){
$title = htmlspecialchars($item->title, ENT_XML1 | ENT_QUOTES, 'UTF-8');
//$websiteUrl = $item->WEB;
$offerUrl = $item->url;
$description = htmlspecialchars($item->description, ENT_XML1 | ENT_QUOTES, 'UTF-8');
$offerTerms = htmlspecialchars($item->terms, ENT_XML1 | ENT_QUOTES, 'UTF-8');
$originalPrice = $item->price_regular;
$finalPrice = $item->price;
$offerDiscount = $item->price_discount;
//$offerSales = $item->SALES;
$offerEnds = $item->expire;
$lat_coordinates = $item->addresses->address->lat;
$lng_coordinates = $item->addresses->address->lng;
$adress = $item->addresses->address->addr;
$hood = $item->addresses->address->section;
$company = $item->company;
//$category = utf8_encode($item->categories->category);
$category = htmlspecialchars($item->categories->category, ENT_XML1 | ENT_QUOTES, 'UTF-8');
$img = $item->image;
mysqli_query($link, "
INSERT INTO `offers` (offerName, offerImgUrl, offerUrl, OfferDetails, offerTerms,
offerRegularPrice, offerDiscount, offerFinalPrice,
offerCategory, offerExpires, offerCompany, offerCity,
offerNeighbourhood)
VALUES ('$title', '$img', '$offerUrl', '".$description."',
'".$offerTerms."', '$originalPrice', '$offerDiscount',
'$finalPrice', '$category', '$offerEnds',
'$company', '$adress', '$hood')") or die(mysqli_error($link));
}
?>
如您所见,我尝试使用 htmlspecial 字符设置 UTF8 编码,我尝试使用 iconv 函数,还使用 mysqli_query 设置名称 utf8,但插入的数据仍然不可读。当然我的 db 字符集是 utf8_general_ci。
那就是数据库中插入的数据:
解决方案
推荐阅读
- sql - CREATE TABLE AS SELECT 在 vertica 上的性能很差
- .net - 当打印文档中出现 2 个或更多页面时如何创建页面
- sql - 如何从连接表中获取列而不是相邻列
- sql-server - 运行代码时无法识别 CONCAT() 函数
- python - SQLalchemy:允许“链式”构建查询对象?
- sql - 使用 Stack Exchange API 获取帖子标签
- visual-studio - Nuget 不会从源代码管理中恢复包
- reactjs - 我怎么知道我的组件在哪里使用?
- c# - 如何使用 Unity 停止平面检测并删除 ARCore 1.9 中的所有平面?
- angular - 错误 TS2741:类型中缺少属性