【问题标题】:Filtering YouTube Video URL过滤 YouTube 视频 URL
【发布时间】:2012-08-06 15:43:53
【问题描述】:

我正在制作一个 YouTube 工具,但我不明白如何在 PHP 变量中获取视频 ID。假设用户在我的表单中输入一个 youtube 视频 url,它可以是:

http://www.youtube.com/watch?v=YzOt12co4nk&feature=g-vrec

过滤URL并在变量中获取此视频ID的方法是什么?

例如:$vid 会有这个视频 ID,所以它会是 $vid = YzOt12co4nk; 请花点时间描述一下,我是编码初学者!谢谢

【问题讨论】:

标签: php variables youtube


【解决方案1】:

你可以使用正则表达式:

$url = "http://www.youtube.com/watch?v=YzOt12co4nk&feature=g-vrec";
preg_match('/v=([0-9a-zA-Z]+)/', $url, $matches);
$vid = $matches[1];

【讨论】:

  • 我们可以过滤谷歌重定向网址以同样的方式获取该网站的网址吗?假设:我想从这个网址http://www.google.com/url?sa=X&q=http://news.google.com/news/story%3Fncl%3Dhttp://www.tv.com/news/celebrity-high-five-former-child-star-christine-lakin-al-from-step-by-step-on-her-5-favorite-tv-shows-29374/%26hl%3Den%26geo%3Dus&ct=ga&cad=CAcQA 获取$url=www.tv.com/news/celebrity-high-five-former-child-star-christine-lakin-al-from-step-by-step-on-her-5-favorite-tv-shows-29374/ 确切的方法是什么.. 我试过但失败了:(
  • @itistg 您应该发布一个新问题,并附上您尝试过的示例以及对问题的完整描述。
猜你喜欢
  • 2021-07-16
  • 2013-08-06
  • 2015-09-20
  • 2013-10-11
  • 1970-01-01
  • 1970-01-01
  • 2017-07-02
  • 2013-02-17
  • 2013-04-19
相关资源
最近更新 更多