0

Im developing offers website and I'm getting the offers from 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));
        }

?>  

As you can see I tried to set the UTF8 encoding with htmlspecial chars, I tried with iconv function, also with 'set names utf8' with mysqli_query, but inserted data is still unreadable.. Of course my db charset is utf8_general_ci.

Thats the inserted data in the db:

enter image description here

  • Hi. Please could you [edit] your question to include some kind of [mcve]? At the moment, we don't really have much information about what your input and output look like, other than "data is still unreadable", so we would have to just guess, which would be a waste of everyone's time. – IMSoP Mar 11 '19 at 18:16
  • What problem are you trying to solve in the first place? `htmlspecialchars()` looks like a good way to break the feed :-? – Álvaro González Mar 11 '19 at 18:18
  • Please check the first post again, I edited it. The problem is that I get unrearable data in mysql db. – Stephanie Kostova Mar 11 '19 at 18:23
  • 1
    Just seen your edit. Your code is wide open to SQL injection so I guess you're also not calling [mysqli_character_set_name()](http://php.net/mysqli_character_set_name). You'll also need to configure your editor to save files in UTF-8. And of course don't mangle data with `htmlspecialchars()`. – Álvaro González Mar 11 '19 at 18:23
  • Try add the header: `header('Content-type: text/html; charset=utf-8');` – CoursesWeb Mar 11 '19 at 18:28
  • Tried to set header, but not working.. – Stephanie Kostova Mar 11 '19 at 19:08
  • 1
    https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch Mar 11 '19 at 19:17
  • mysqli_character_set_name() worked for me :) Thank you! – Stephanie Kostova Mar 11 '19 at 21:12
  • Possible duplicate of [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – user3783243 Mar 11 '19 at 21:30

0 Answers0