I have searched through lots of questions but I can't find the correct solution as Facebook changed it's URL strategies. For example: if the video URL is
https://www.facebook.com/yourstartupsIndia/videos/977323192329199/
How can I get the video id from the url. ie : 977323192329199
答案 0 :(得分:0)
正则表达式(\d+)/$
,\d
表示任何数字,/$
表示以/
结尾
preg_match("#(\d+)/$#", 'https://www.facebook.com/yourstartupsIndia/videos/977323192329199/', $vid);
echo $vid[1];
# 977323192329199
答案 1 :(得分:0)
对于非正则表达式解决方案,请考虑以下因素:
代码:(Demo)
$url='https://www.facebook.com/yourstartupsIndia/videos/977323192329199/';
//string functions:
echo substr($url,strrpos(rtrim($url,'/'),'/')+1,-1);
echo "\n\n";
//array functions:
echo array_slice(explode('/',$url),-2,1)[0];
输出:
977323192329199
977323192329199