penev75
Member
Имам малък проблем с генерирането на RSS в сайта ми за малки обяви. Сайта ми изцяло е на UTF-8, но при генерирането на RSS емисиите за отделните градове се получава това:
Кода който генерира това е следния:
Освен грешните символи, които се генерират понякога генерирания файл се приема от RSS четците, като грешен и те не го прочитат.
Ще се радвам, ако якой разбиращ от PHP прочете кода и ми даде съвет как да оправя проблема.
Код:
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">
<channel>
<title><![CDATA[Малки обÑви]]></title>
<description><![CDATA[ПоÑледни обÑви в ÐºÐ°Ñ‚ÐµÐ³Ð¾Ñ€Ð¸Ñ Ð¾Ñ‚ град ОблаÑÑ‚ Стара Загора]]></description>
<link>http://bgobiavi.info/</link>
<lastBuildDate>Thu, 25 Jun 2009 21:39:26 +0300</lastBuildDate>
<item>
<title><![CDATA[Чанти и акÑеÑоари от еÑтеÑтвена кожа (Плевен)]]></title>
<link>http://bgobiavi.info/-1/posts/_/88_pokupko_prodajba/45_chanti_i_aksesoari_ot_estestvena_koja.html</link>
<description><![CDATA[Предлагаме голÑмо разнообразие на чанти, портмонета,гривни, калъфи за GSM и други акÑеÑоари от еÑтеÑтвена кожа на едро и дребно от производител. Ð’Ñичко на Ñайта ...
Кода който генерира това е следния:
Код:
<?php
require_once("initvars.inc.php");
require_once("config.inc.php");
header("Content-Type: text/xml; charset=UTF-8");
// Location condition
if($xcityid > 0)
{
$loc_condn = $city_condn = "AND a.cityid = $xcityid";
}
else
{
$loc_condn = $country_condn = "AND ct.countryid = $xcountryid";
}
if ($xview == "events")
{
$where = "";
if ($xsearch)
{
$searchsql = mysql_escape_string($xsearch);
$where = "(a.adtitle LIKE '%$searchsql%' OR a.addesc LIKE '%$searchsql%') AND a.endon >= NOW()";
}
else if ($xdate)
{
$where = "(starton <= '$xdate' AND endon >= '$xdate')";
}
else
{
$where = "starton >= NOW()";
}
if($_GET['area']) $where .= "AND a.area = '$_GET[area]'";
// Get results
$sql = "SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp,
UNIX_TIMESTAMP(a.starton) AS starton, UNIX_TIMESTAMP(a.endon) AS endon,
COUNT(*) AS piccount, p.adid AS haspics
FROM $t_events a
INNER JOIN $t_cities ct ON a.cityid = ct.cityid
LEFT OUTER JOIN $t_adpics p ON a.adid = p.adid AND p.isevent = '1'
WHERE $where
AND $visibility_condn
$loc_condn
GROUP BY a.adid
ORDER BY a.createdon DESC
LIMIT $rss_itemcount";
$res = mysql_query($sql) or die($sql.mysql_error());
// Vars
$target_view = "showevent";
$target_view_sef = "events";
if ($xdate) $link_extra = "&date=$xdate";
else $find_date = TRUE;
}
else
{
// Make up the sql query
$whereA = array();
if ($xsearch)
{
$searchsql = mysql_escape_string($xsearch);
$whereA[] = "(a.adtitle LIKE '%$searchsql%' OR a.addesc LIKE '%$searchsql%')";
}
if($_GET['area']) $whereA[] = "a.area = '$_GET[area]'";
if ($xsubcathasprice && $_GET['pricemin'])
{
$whereA[] = "a.price >= $_GET[pricemin]";
}
if ($xsubcathasprice && $_GET['pricemax'])
{
$whereA[] = "a.price <= $_GET[pricemax]";
}
if ($xsubcatid) $whereA[] = "a.subcatid = $xsubcatid";
else if ($xcatid) $whereA[] = "scat.catid = $xcatid";
if (is_array($_GET['x']) && count($_GET['x']))
{
foreach ($_GET['x'] as $fldnum=>$val)
{
// Ensure numbers
$fldnum += 0;
if (!$val || !$fldnum) continue;
if($xsubcatfields[$fldnum]['TYPE'] == "N" && is_array($val))
{
numerize($val['min']); numerize($val['max']); // Sanitize
if($val['min']) $whereA[] = "axf.f{$fldnum} >= $val[min]";
if($val['max']) $whereA[] = "axf.f{$fldnum} <= $val[max]";
}
elseif($xsubcatfields[$fldnum]['TYPE'] == "D")
{
$whereA[] = "axf.f{$fldnum} = '$val'";
}
else
{
$whereA[] = "axf.f{$fldnum} LIKE '%$val%'";
}
}
}
$where = implode(" AND ", $whereA);
if (!$where) $where = "1";
// Get results
$sql = "SELECT a.*, UNIX_TIMESTAMP(a.createdon) AS timestamp,
COUNT(*) AS piccount, p.adid AS haspics, scat.subcatname AS subcatname, scat.catid as catid
FROM $t_ads a
INNER JOIN $t_cities ct ON a.cityid = ct.cityid
INNER JOIN $t_subcats scat ON a.subcatid = scat.subcatid
LEFT OUTER JOIN $t_adxfields axf ON a.adid = axf.adid
LEFT OUTER JOIN $t_adpics p ON a.adid = p.adid AND p.isevent = '0'
WHERE $where
AND $visibility_condn
$loc_condn
GROUP BY a.adid
ORDER BY a.createdon DESC
LIMIT $rss_itemcount";
$res = mysql_query($sql) or die($sql.mysql_error());
// Vars
$target_view = "showad";
$target_view_sef = "posts";
}
if (mysql_num_rows($res)) {
$firstRow = mysql_fetch_array($res);
$lastBuildDate = $firstRow['timestamp'];
mysql_data_seek($res, 0);
} else {
$lastBuildDate = time();
}
echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>';
?>
<rss version="2.0">
<channel>
<title><![CDATA[<?php echo str_replace("{@SITE_NAME}", $site_name, str_replace("{@CATEGORY}", ($xsubcatname?$xsubcatname:$xcatname), str_replace("{@CITY}", $xcityname, $lang['RSS_CHANNEL_TITLE']))); ?>]]></title>
<description><![CDATA[<?php echo str_replace("{@SITE_NAME}", $site_name, str_replace("{@CATEGORY}", ($xsubcatname?$xsubcatname:$xcatname), str_replace("{@CITY}", $xcityname, $lang['RSS_CHANNEL_DESC']))); ?>]]></description>
<link><?php echo $script_url; ?>/</link>
<lastBuildDate><?php echo date("r", $lastBuildDate); ?></lastBuildDate>
<?php
if (@mysql_num_rows($res))
{
if($xview == "events")
{
$i = 0;
while($row=mysql_fetch_array($res))
{
$i++;
if($sef_urls)
{
if ($find_date) $urldate = date("Y-m-d", $row['starton']);
$url = "{$vbasedir}$xcityid/$target_view_sef/$urldate/$row[adid]_" . RemoveBadURLChars($row['adtitle']) . ".html";
}
else
{
if ($find_date) $link_extra = "&date=".date("Y-m-d", $row['starton']);
$url = "?view=$target_view&adid=$row[adid]&cityid=$xcityid{$link_extra}";
}
?>
<item>
<title><![CDATA[<?php
echo date("M j", $row['starton']);
if($row['starton'] != $row['endon']) echo "-".date("M j", $row['endon']);
echo ": " . ($row['adtitle']);
if($row['area']) echo (" ($row[area])"); ?>]]></title>
<link><?php echo "$script_url/$url"; ?></link>
<description><![CDATA[<?php
$row['addesc'] = strip_tags($row['addesc']);
$desc = substr(strip_tags($row['addesc']), 0, $rss_itemdesc_chars);
if(strlen($row['addesc'])>$rss_itemdesc_chars)
{
if(strpos($desc, "&") !== FALSE && (strpos($desc, ";") === FALSE || strrpos($desc, ";") < strrpos($desc, "&")))
$desc = substr($row['addesc'], 0, strpos($row['addesc'], ";", $rss_itemdesc_chars)+1);
$desc .= "...";
}
echo $desc;
?>]]></description>
<pubDate><?php echo date("r", $row['timestamp']); ?></pubDate>
</item>
<?php
}
}
else
{
$i = 0;
while($row=mysql_fetch_array($res))
{
$i++;
if($sef_urls)
{
$catname_inurl = RemoveBadURLChars($xcatname);
$subcatname_inurl = RemoveBadURLChars($row['subcatname']);
$url = "{$vbasedir}$xcityid/$target_view_sef/{$xcatid}_{$catname_inurl}/{$row[subcatid]}_{$subcatname_inurl}/$row[adid]_" . RemoveBadURLChars($row['adtitle']) . ".html";
}
else
{
$url = "?view=$target_view&adid=$row[adid]&cityid=$xcityid{$link_extra}";
}
?>
<item>
<title><![CDATA[<?php
echo ($row['adtitle']);
if($row['area']) echo (" ($row[area])");
if($xsubcathasprice && $row['price']) echo " - ".$currency.$row['price'] ?>]]></title>
<link><?php echo "$script_url/$url"; ?></link>
<description><![CDATA[<?php
$row['addesc'] = strip_tags($row['addesc']);
$desc = substr($row['addesc'], 0, $rss_itemdesc_chars);
if(strlen($row['addesc'])>$rss_itemdesc_chars)
{
if(strpos($desc, "&") !== FALSE && (strpos($desc, ";") === FALSE || strrpos($desc, ";") < strrpos($desc, "&")))
$desc = substr($row['addesc'], 0, strpos($row['addesc'], ";", $rss_itemdesc_chars)+1);
$desc .= "...";
}
echo $desc;
?>]]></description>
<pubDate><?php echo date("r", $row['timestamp']); ?></pubDate>
</item>
<?php
}
}
}
?>
</channel>
</rss>
Освен грешните символи, които се генерират понякога генерирания файл се приема от RSS четците, като грешен и те не го прочитат.
Ще се радвам, ако якой разбиращ от PHP прочете кода и ми даде съвет как да оправя проблема.