Get Youtube Video ID from html code with PHP

后端 未结 5 1916
小蘑菇
小蘑菇 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:15

    I might get scolded for using a regex to parse html but given the circumstances maybe it's the best way to do it?

    preg_match('~/v/([0-9a-z_]+)~i', $code, $matches);
    echo $matches[1];
    

    assuming the valid characters for a youtube video id are 0-9a-z_

提交回复
热议问题