问题是,此方法仅适用于一个视频。 并且是链接后的文字(http://www.youtube.com/watch?v=ID精彩视频!)然后不起作用。
<?php
if (strpos($content, 'http://www.youtube.com/watch?v=') !== false) {
$content = str_replace("http://www.youtube.com/watch?v=$id", '<object width="' . $width . '" height="' . $height . '"><param name="movie" value="http://www.youtube.com/v/' . $id . '&hl=en_US&fs=1?rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $id . '&hl=en_US&fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . $width . '" height="' . $height . '"></embed></object>', $content);
} else if (strpos($content, 'https://www.youtube.com/watch?v=') !== false) {
$content = str_replace("https://www.youtube.com/watch?v=$id", '<object width="' . $width . '" height="' . $height . '"><param name="movie" value="https://www.youtube.com/v/' . $id . '&hl=en_US&fs=1?rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/' . $id . '&hl=en_US&fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . $width . '" height="' . $height . '"></embed></object>', $content);
}
?>