使用,它会返回YouTube的嵌入链接。
将你的YouTube网址传入函数,然后它会返回嵌入代码链接。
中的functions.php
function parseVideos($videoString = null)
{
if (strpos($videoString, 'youtube.com/embed') !== FALSE)
{
return $videoString;
}
if (strpos($videoString, 'iframe') !== FALSE)
{
// retrieve the video url
$anchorRegex = '/src="(.*)?"/isU';
$results = array();
if (preg_match($anchorRegex, $video, $results))
{
$link = trim($results[1]);
}
}
else
{
// we already have a url
$link = $videoString;
}
if (strpos($link, 'youtube.com') !== FALSE) {
preg_match(
'/[\\?\\&]v=([^\\?\\&]+)/',
$link,
$matches
);
//the ID of the YouTube URL: x6qe_kVaBpg
$id = $matches[1];
return '//www.youtube.com/embed/'.$id;
}
else if (strpos($link, 'youtu.be') !== FALSE) {
preg_match(
'/youtu.be\/([a-zA-Z0-9_]+)\??/i',
$link,
$matches
);
$id = $matches[1];
return '//www.youtube.com/embed/'.$id;
}
else if (strpos($link, 'player.vimeo.com') !== FALSE) {
// works on:
// http://player.vimeo.com/video/37985580?title=0&byline=0&portrait=0
$videoIdRegex = '/player.vimeo.com\/video\/([0-9]+)\??/i';
preg_match($videoIdRegex, $link, $matches);
$id = $matches[1];
return '//player.vimeo.com/video/'.$id;
}
else if (strpos($link, 'vimeo.com') !== FALSE) {
//extract the ID
preg_match(
'/\/\/(www\.)?vimeo.com\/(\d+)($|\/)/',
$link,
$matches
);
//the ID of the Vimeo URL: 71673549
$id = $matches[2];
return '//player.vimeo.com/video/'.$id;
}
return $videoString;
// return data
}
,你想在同一个窗口中打开视频吗? –
不打开任何地方,我只需要变成自定义字段值video_url的PHP代码,其中链接到single.php内的完整iframe与函数,所以我实际上并没有改变single.php值。 –
可以请你举个例子。 –