首页 > 解决方案 > 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。

那就是数据库中插入的数据:

在此处输入图像描述

标签: phpencodingrss

解决方案


推荐阅读