我将尝试使用以下函数将标准的Youtube URL转换为嵌入式URL:
然而,当我运行它时,出现了以下错误:
我试图使用以下功能将标准的YouTube URL转换为嵌入式URL:
<?php
$url = 'https://www.youtube.com/watch?v=oVT78QcRQtU';
function getYoutubeEmbedUrl($url)
{
$shortUrlRegex = '/youtu.be\/([a-zA-Z0-9_]+)\??/i';
$longUrlRegex = '/youtube.com\/((?:embed)|(?:watch))((?:\?v\=)|(?:\/))(\w+)/i';
if (preg_match($longUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
if (preg_match($shortUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
return 'https://www.youtube.com/embed/' . $youtube_id ;
}
getYoutubeEmbedUrl();
然而,当我运行它时,出现了以下错误:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function getYoutubeEmbedUrl()
我不明白为什么我只有一个参数并且已经提供了它,但还是提示我参数太少?