0

有谁知道<embed>使用php从Vimeo标签中提取视频ID的正则表达式?

例如:

13084859

从:

<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13084859&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>
4

2 回答 2

3

这里:

$html = '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13084859&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>';

if (preg_match('/moogaloop\.swf\?clip_id=([0-9]+)/', $html, $matches)) {
  echo $matches[1];
} else {
  echo 'n/a';
}
于 2010-07-09T17:13:57.347 回答
0

这是我为您编写的一个简单函数,工作正常,但它不使用正则表达式:)

<?php
function get_vimeo_id( $embed )
{
    $vimeo_id_array = explode( '?clip_id=', $embed );
    $vimeo_id_array_2 = explode( '&amp;', $vimeo_id_array[1] );
    $vimeo_id = $vimeo_id_array_2[0];

    return $vimeo_id;
}

// Get Vimeo Id
$vimeo_id = get_vimeo_id( '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13084859&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>' );

// Use $vimeo_id
echo $vimeo_id;
?>
于 2010-07-09T16:49:55.447 回答