我正在使用WordPress插件输出文本链接,但用户输入来自第三方网站的链接。 链接是youtu.be格式,我需要视频的ID。 我尝试过这种方法,但到目前为止我还没有尝试过
原始代码:
if($video_link != "") { echo '<p>'; echo 'Please visit : <a href="'. $video_link .'"> Multimedia link </a> for more photos and information' ; echo '</p>'; }输出链接:
http://youtu.be/abcdefghijkl
试过这个,不能让它工作:
if($video_link != "") { $url = $_GET['url']; $video_id = substr( parse_url($url, PHP_URL_PATH), 1 ); echo '<iframe width="560" height="315" src="https://www.youtube.com/embed'.$video_id.'" frameborder="0" allowfullscreen></iframe>' ; }输出iframe不起作用:
I'm working with a WordPress plugin that outputs a text link, but the user inputs the link from an 3rd party site. the links are youtu.be format, I need the video's ID. I have tried this method but I'm not getting it so far
original code:
if($video_link != "") { echo '<p>'; echo 'Please visit : <a href="'. $video_link .'"> Multimedia link </a> for more photos and information' ; echo '</p>'; }Output link :
http://youtu.be/abcdefghijkl
tried this, can't get it to work:
if($video_link != "") { $url = $_GET['url']; $video_id = substr( parse_url($url, PHP_URL_PATH), 1 ); echo '<iframe width="560" height="315" src="https://www.youtube.com/embed'.$video_id.'" frameborder="0" allowfullscreen></iframe>' ; }Output Iframe does not work :
最满意答案
编辑:忽略我以前的答案,你的解析工作正常。 你忘记了iframe src属性中的'embed'之后的/ 。
或者如果你愿意,你可以删除你的解析中的substr部分(这是剥离斜线的部分)
$video_id = parse_url($url, PHP_URL_PATH);EDIT: Ignore my previous answer, your parse works fine. You just forgot the / after 'embed' in your iframe src attribute.
Or if you want, you can just remove the substr part in your parse (which is what strips the slash)
$video_id = parse_url($url, PHP_URL_PATH);更多推荐
发布评论