Get Youtube Video ID from html code with PHP

后端 未结 5 1928
小蘑菇
小蘑菇 2020-11-27 06:49

I want to get all only youtube video ID from html code

look the (or multiple) object/embed code for youtube video

// html from database

    &         


        
5条回答
  •  无人及你
    2020-11-27 07:34

    If you want to get embed link for youtube video, you can use the following code snippet:

    $youtubeRegexp = "#(/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#";
    $embedUrl = preg_replace($youtubeRegexp, '/embed/$2', $videoUrl);
    

    For the current moment embed code is:

    
    

    Note: $videoUrl should be set to the original url prior to running this expression.

提交回复
热议问题