【发布时间】:2013-04-14 10:21:19
【问题描述】:
如何使用 PHP 从文本中分解所有 Youtube 嵌入值?例如我有文字:
Fails: <iframe width="560" height="315" src="http://www.youtube.com/embed/Ujwod-vqyqA" frameborder="0" allowfullscreen></iframe>
More fails: <iframe width="560" height="315" src="http://www.youtube.com/embed/DYRTzXSYixQ" frameborder="0" allowfullscreen></iframe>
More the more: <iframe width="560" height="315" src="http://www.youtube.com/embed/uLWqUW_U6dQ" frameborder="0" allowfullscreen></iframe>
我想使用为我的 Facebook 帖子嵌入的所有视频之一,例如第一个视频嵌入:
https://i3.ytimg.com/vi/Ujwod-vqyqA/mqdefault.jpg
我该怎么做?我试过strpos,但这不起作用。
【问题讨论】:
-
我尝试使用“strpos”,但它只给出了一个数字,嵌入在哪里。我想到了“爆炸”,但我不知道这怎么可能……应该是这样的:获取所有“youtube.com/embed/*”并将其插入数组中,然后我可以从中选择
-
你的开发方法是什么?发布您尝试过的代码片段会有所帮助。
-
我不知道该怎么做,这就是我在这里问的原因。就像我说的,我试过了: $youtube_look = "youtube.com/embed"; $youtube_embed = strpos($article, $youtube_look);但它只给了我数字
-
所以基本上像这样的东西应该可以完成这项工作吗?
preg_match_all('/<iframe.*?src="(http(?:s)?:\/\/(?:www.)youtube.com\/embed\/.*?)".*?>/i', file_get_contents('yourfile.txt'), $m); print_r($m[1]);
标签: php