📜  php 替换 youtube 嵌入 url - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:08.803000             🧑  作者: Mango

代码示例2
$youtubeUrl = 'https://www.youtube.com/watch?v=1cQh1ccqu8M';
$youtubePattern = "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i";
function youtubeEmbedCallback($matches) {
    if (!isset($matches[2])) {
        return '';
    }
    $videoId = $matches[2];
    return '';
}
$youtubeEmbed = preg_replace_callback($youtubePattern, "youtubeEmbedCallback", $youtubeUrl);
echo $youtubeEmbed;
//Stamperà:
//