我知道这个问题已经很老了,但我会回答以防万一有人点击它寻找相同的东西。
将 oEmbed (http://oembed.com/) 用于 YouTube、Vimeo、Wordpress、Slideshare、Hulu、Flickr 和许多其他服务。如果不在列表中,或者您想让它更精确,您可以使用:
http://simplehtmldom.sourceforge.net/
它是一种用于 PHP 的 jQuery,这意味着您可以使用 HTML 选择器来获取部分代码(即:所有图像、获取 div 的内容、仅返回节点的文本(无 HTML)内容等)。
你可以做这样的事情(可以做得更优雅,但这只是一个例子):
require_once("simple_html_dom.php");
function getContent ($item, $contentLength)
{
$raw;
$content = "";
$html;
$images = "";
if (isset ($item->content) && $item->content != "")
{
$raw = $item->content;
$html = str_get_html ($raw);
$content = str_replace("\n", "<BR /><BR />\n\n", trim($html->plaintext));
try
{
foreach($html->find('img') as $image) {
if ($image->width != "1")
{
// Don't include images smaller than 100px height
$include = false;
$height = $image->width;
if ($height != "" && $height >= 100)
{
$include = true;
}
/*else
{
list($width, $height, $type, $attr) = getimagesize($image->src);
if ($height != "" && $height >= 100)
$include = true;
}*/
if ($include == true)
{
$images = $images . '<div class="theImage"><a href="'.$image->src.'" title="'.$image->alt.'"><img src="'.$image->src.'" alt="'.$image->alt.'" class="postImage" border="0" /></a></div>';
}
}
}
}
catch (Exception $e) {
// Do nothing
}
$images = '<div id="images">'.$images.'</div>';
}
else
{
$raw = $item->summary;
$content = str_get_html ($raw)->plaintext;
}
return (substr($content, 0 , $contentLength) . (strlen ($content) > $contentLength ? "..." : "") . $images);
}