我几乎完全依靠自己来解决这个问题,几乎不了解PHP,并且迫切需要帮助。重新设计的Wordpress新闻网站的Feed的描述标签中包含了图像,我们已经设置了一种提取这些图像的方法,因此现在其他站点上的Feed都翻了一番。我想关闭在描述标签中提取的图像,但在弄清楚如何完成该操作时遇到了麻烦。
我尝试了一些操作,例如strip_tag,改组代码/ HTML等,但是我怀疑我的大部分问题都不知道在哪里或如何实现它们。
if ($rss = simplexml_load_file($feed)){ // (replace relative path with variable: $rssPath ).
$count = 0;
foreach($rss->channel->item as $item){
if ($count < $items) {
/*Set variables from RSS*/
$title = $item->title;
$desc = $item->description;
$content = htmlspecialchars_decode($item->children('content', true)->encoded);
preg_match('/(<img[^>]+>)/i', $content,
$content_image);
//if(strstr($content, 'img')){
// $content_trunc =
substr($content,0,strpos($content,'</p>', 550)) . "...";
//}
//else {
//$content_trunc = substr($content,0,strpos($content,'</p>', 400)) .
"...";
//}
$content_image = str_replace('class="',
'class="media-object ', $content_image);
$link = $item->link;
$pubdate = $item->pubDate;
$pubMonth = substr($pubdate, 8, 3);
$pubDay = substr($pubdate, 5, 2);
/*Display items*/
$output= "<div class='row'>\n<div class='col-md-3'>";
$output = $output .
" <a href='". $link ."'>"
. $content_image[0] .
" </div>
<div class='col-md-9'><span class='news-headline' style='vertical-align:top;'>" . $title . "</span>
</a>" . "\n
<p class='news-blurb'>" . $desc . "</p>
</div>\n</div>\n <hr />";
echo $output;
$count++;
}
}
简而言之,这是说明标签:
<description><![CDATA[<img width="150" height="150" src="http://placehold.it/150.150" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" />news article description here [...]]]></description>
请帮助!这是我想学习的语言,但距离我还有很长的路要走。我所知道的是,我需要从$ desc中过滤掉内容。但我不知道如何。
答案 0 :(得分:0)
在preg_replace("/<img[^>]+\>/i", "", $desc);
行之后尝试$desc = $item->description;
。