Проблема с кодировкой RSS - PullRequest
0 голосов
/ 11 марта 2019

Я занимаюсь разработкой сайта предложений, и я получаю предложения из 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));
        }

?>  

Как вы можете видеть, я пытался установить кодировку UTF8 с помощью htmlspecial chars, я пытался с помощью функции iconv, также с 'set names utf8' с mysqli_query, но вставленные данные по-прежнему не читаются. Конечно, моя кодировка БД - это utf8_general_ci.

То есть вставленные данные в БД:

enter image description here

...