我正在将rss feed插入到mysql中,例如:
$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);
//$websiteUrl = $item->WEB;
$offerUrl = $item->url;
$description = htmlspecialchars($item->description);
$offerTerms = htmlspecialchars($item->terms);
$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 = htmlspecialchars($item->addresses->address->addr);
$hood = htmlspecialchars($item->addresses->address->section);
$company = htmlspecialchars($item->company);
//$category = utf8_encode($item->categories->category);
$category = htmlspecialchars($item->categories->category);
$img = $item->image;
mysqli_set_charset($link, 'utf8mb4');
$query = 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));
}
当我运行脚本时,它会从Feed中添加6个结果并返回错误:
您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以获取在第5行的
's Vision</b> и се радвайте на перфектна визия! '
附近使用正确的语法
我认为特殊字符有问题,但添加了htmlspecialchars函数,并且无法再次使用。