私がこれまでに試したのは、この機能です:
function isYoutubeUrl($url) {
return preg_match("#^https?://(?:www\.)?youtube.com#", $url);
}
ただし、次のような単純な youtube 文字列でのみ機能します。
$string = 'http://www.youtube.com/watch?v=bJIXm6U4df';
$newString = isYoutubeURL($string);
if($newString); // true
YouTube URL の文字列をチェックし、存在する場合はその URL を返す関数が必要です。
$string = 'this is so crazy...http://www.youtube.com/watch?v=bJIXm6U4df';
$newString = extractYoutubeUrl($string);
echo $newString; // http://www.youtube.com/watch?v=bJIXm6U4df
何か案が?