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

后端 未结 8 1790
感情败类
感情败类 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 02:02

    Since all you want to do is check for the presence of a string, use stripos. If it doesn't have youtube.com or vimeo.com in it, the url is malformed, right? stripos is case insensitive, too.

    if(stripos($url,'youtu')===false){
        //must be vimeo
        } else {
        //is youtube
        }
    

提交回复
热议问题