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,
You can try my solution:
function checkServer( $domains=array(), $url ) {
foreach ( $domains as $domain ) {
if ( strpos($url, $domain ) > 0) {
return true;
} else {
return false;
}
}
}
Use:
if( checkServer(array("youtube.com","youtu.be"), $url ) ) {
//is Youtube url
}
elseif( checkServer(array("vimeo.com"), $url ) ) {
//is Vimeo
}
elseif ( checkServer(array("any domain"), $url ) ) {
//is Any Domain
}else {
//unknow domain
}