gpt4 book ai didi

php - Joomla-简单的RSS阅读器,可获取Youtube视频ID

转载 作者:行者123 更新时间:2023-12-03 05:42:59 24 4
gpt4 key购买 nike

我正在尝试修改简单RSS阅读器以获取RSS中某个项目的Youtube视频ID来确定缩略图,我似乎处在正确的轨道上,但对于PHP来说却不是很好-这是来自helper.php,一旦完成就可以许多其他人使用它来为Joomla修改自己的Simple RSS Reader Mod。

我想知道如何使此函数“getYTid”将ID放在URL Veriable的末尾-代码在两个位置@函数中关闭,并且在末尾声明变量不仅是我要怎么做,但是如果可能的话,请把我带到一个我可以更好地理解使用混合文本声明变量的语法的地方,如果可能的话,我似乎经常遇到这个问题

function getYTid('$feed->itemLink') {

$ytvIDlen = 11; // This is the length of YouTube's video IDs

// The ID string starts after "v=", which is usually right after
// "youtube.com/watch?" in the URL
$idStarts = strpos($ytURL, "?v=");

// In case the "v=" is NOT right after the "?" (not likely, but I like to keep my
// bases covered), it will be after an "&":
if($idStarts === FALSE)
$idStarts = strpos($ytURL, "&v=");
// If still FALSE, URL doesn't have a vid ID
if($idStarts === FALSE)
die("YouTube video ID not found. Please double-check your URL.");

// Offset the start location to match the beginning of the ID string
$idStarts +=3;

// Get the ID string and return it
$ytvID = substr($ytURL, $idStarts, $ytvIDlen);

return $ytvID;

}
$feedItem->feedImageSrc = 'http://i3.ytimg.com/vi/'$ytvID'/default.jpg';

最佳答案

这是一个工作示例,您可以轻松调整它以使其适合您:

function get_yt_id($yturl, $idlen) {

$idchk_que = strpos($yturl, "?v=");
$idchk_amp = strpos($yturl, "&v=");

if ($idchk_que > -1 || $idchk_amp > -1) {

if ($idchk_que > -1) {

$yturl_exploded = explode("?v=", $yturl);

}
else if ($idchk_amp > -1) {

$yturl_exploded = explode("&v=", $yturl);

}
$yturl_exp = $yturl_exploded[1];
$ytid = substr($yturl_exp, 0, $idlen);

return $ytid;

}
else {

return "ID NOT FOUND";

}

}

$id_from_yturl = get_yt_id("http://www.youtube.com/watch?v=YvbQ9G0yXeU&t=14m36s", "11");

print $id_from_yturl;
  • 我做了一些编辑,以便此功能更可靠...
  • 关于php - Joomla-简单的RSS阅读器,可获取Youtube视频ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12645625/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com