PHP: How to check whether the URL is Youtube's or vimeo's

后端 未结 8 2011
感情败类
感情败类 2021-02-02 01:19

How can I write a function to check whether the provided URLs is youtube or vimeo?

For instance, I have this two URLs that I store in a database as strings,



        
8条回答
  •  面向向阳花
    2021-02-02 01:43

    You can use preg_match():

    $u1="http://vimeo.com/24456787";
    $u2="http://www.youtube.com/watch?v=rj18UQjPpGA&feature=player_embedded";
    
    if(preg_match('/http:\/\/(www\.)*vimeo\.com\/.*/',$u1)){
        // do vimeo stuff
        echo "Vimeo URL found!\n";
    }
    
    if(preg_match('/http:\/\/(www\.)*youtube\.com\/.*/',$u2)){
        // do youtube stuff
        echo "YouTube URL found!\n";
    }
    

提交回复
热议问题