YouTube Vimeo Video ID from Embed Code or From URL with PHP Regular Expression RegEx

前端 未结 4 1285
轮回少年
轮回少年 2021-02-01 10:09

I want to get Video ID for YouTube or Vimeo via its Embed code or from URL, Any solution to do this with PHP ?

4条回答
  •  温柔的废话
    2021-02-01 10:50

    According to the latest youtube standard, you can use following code to extract video id from embed code.

    $embed = '';
    preg_match('~embed/(.*?)"~', $embed, $output);
    echo $output[1];
    

    Thank you

提交回复
热议问题