Php 为RSS提要制作slug
我想创建指向RSS帖子的链接,但我需要一个“slug”。我想用“-”替换空格,这样我就可以将链接重定向到我在wordpress网站上的帖子。我的RSS:Php 为RSS提要制作slug,php,rss,slug,Php,Rss,Slug,我想创建指向RSS帖子的链接,但我需要一个“slug”。我想用“-”替换空格,这样我就可以将链接重定向到我在wordpress网站上的帖子。我的RSS: <?php include("connect.inc.php"); $items = mysql_query("select * from dailynewsitems where actief = '1' and pubDate <= NOW() order by id DESC limit 15"); echo
<?php
include("connect.inc.php");
$items = mysql_query("select * from dailynewsitems where actief = '1' and pubDate <= NOW() order by id DESC limit 15");
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">
<channel>
<title>Nieuwsfeed WebGiants Financieel</title>
<description>Nieuwsfeed WebGiants</description>
<link>http://modules.publiceer.net/nieuwsfeed_webgiants2012.php</link>
<language>nl</language>";
while ($item = mysql_fetch_object($items)) {
$id = $item->id;
$title = $item->title;
$description = $item->description;
$longdesc = $item->longdesc;
list($d, $m, $y) = explode("-", $item->pubDate);
echo '<item>';
echo '<guid>' . $item->id . '</guid>';
echo '<title>' . htmlspecialchars($title) . '</title>';
echo 'DATUM<pubDate>' . date("D", mktime(0, 0, 0, $m, $d, $y)) . ', ' . $d . ' ' . date("M", strtotime($item->pubDate)) . ' ' . $y . ' 00:00:00 CST</pubDate>';
echo '<description>' . htmlspecialchars($description) . '</description>';
echo '<longdesc>' . htmlspecialchars($longdesc) . '</longdesc>';
echo "<link>http://www.webgiants.nl/geen-categorie/".$item->title."</link>";
echo '</item>';
}
echo "</channel>";
echo "</rss>";
只需使用str\u replace函数即可
echo”http://www.webgiants.nl/geen-categorie/.str_替换(“,”-“,$item->title)。”;
我会首先将mysql函数更改为mysqli函数,因为mysql已被弃用 谢谢你的回答。我如何实现它?我使用了$slug=str_replace(“,“-”,$title)$slug=$item->slug;回声“鼻涕虫”,鼻涕虫;但这不起作用
echo "<link>http://www.webgiants.nl/geen-categorie/".str_replace(" ", "-", $item->title)."</link>";