有谁知道使用 php 从 Vimeo 嵌入中提取视频 ID 的正则表达式?

发布于 2024-09-09 04:23:08 字数 844 浏览 2 评论 0原文

有谁知道使用 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>

Does anyone know a regexp to extract just the video id from a Vimeo <embed> tag using php?

eg:

13084859

from:

<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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初懵 2024-09-16 04:23:08

这里:

$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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&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';
}

Here:

$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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&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';
}
风吹雪碎 2024-09-16 04:23:08

这是我为您编写的一个简单函数,运行良好,但它不使用正则表达式:)

<?php
function get_vimeo_id( $embed )
{
    $vimeo_id_array = explode( '?clip_id=', $embed );
    $vimeo_id_array_2 = explode( '&', $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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>' );

// Use $vimeo_id
echo $vimeo_id;
?>

Here is a simple function I've written for you, is working fine, but its not using regex :)

<?php
function get_vimeo_id( $embed )
{
    $vimeo_id_array = explode( '?clip_id=', $embed );
    $vimeo_id_array_2 = explode( '&', $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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>' );

// Use $vimeo_id
echo $vimeo_id;
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文