<?php
define('HAZELFENCES_WEBSITE', 'https://test.com');
$text = '[youtube]https://www.youtube.com/watch?v=xHLE2LTAItw&t=53s[/youtube]';
$text .= '[youtube]https://www.youtube.com/watch?v=xHLE2LTAItw[/youtube]';
if (preg_match_all("/\[youtube\]((\s|.)+?)\[\/youtube\]/i", $text, $matches)) {
$allMatches = count($matches[0]);
if (is_array($matches[0]) && $allMatches > 0) {
for ($i = 0; $i < $allMatches; $i++) {
$text = str_replace("watch?v=", "embed/", $text);
if (strpos($matches[0][$i], "&t=") !== false) {
$text = str_replace("&t=", "?start=", $text);
$text = preg_replace("#s\[\/youtube\]#i", "&enablejsapi=1&origin=". HAZELFENCES_WEBSITE ."[/youtube]", $text);
} else {
$text = preg_replace("#\[\/youtube\]#i", "?enablejsapi=1&origin=". HAZELFENCES_WEBSITE ."[/youtube]", $text);
}
}
$text = preg_replace("/\[youtube\]((\s|.)+?)\[\/youtube\]/i", "<iframe width=\"640\" height=\"510\" src=\"\\1\" loading=\"lazy\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>", $text);
}
}
echo $text;
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- <iframe width="640" height="510" src="https://www.youtube.com/embed/xHLE2LTAItw?start=53&enablejsapi=1&origin=https://test.com?enablejsapi=1&origin=https://test.com" loading="lazy" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><iframe width="640" height="510" src="https://www.youtube.com/embed/xHLE2LTAItw?enablejsapi=1&origin=https://test.com" loading="lazy" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
preferences:
185.14 ms | 408 KiB | 5 Q