我知道这个问题是相当古老的,但我会回答,以防万一有人打它寻找同样的事情。
为YouTube,Vimeo,Wordpress,Slideshare,Hulu,Flickr和许多其他服务使用oEmbed(http://oembed.com/)。如果不在列表中,或者你想让它更精确,您可以使用此:
http://simplehtmldom.sourceforge.net/
这是一个老的jQuery的PHP的,这意味着你可以使用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);
}
试着问一个更直接的问题,如“我怎么找一部电影的缩略图在使用PHP的YouTube中“这可能会让人们更敏感。 – 2009-09-05 20:17:27