dongxian8858 2016-11-28 23:44
浏览 44
已采纳

PHP中的iframe和SQL中的字符串

I'm trying to convert a YouTube video link to You Tube embed link. A string will receive the YouTube link from SQL, another code will convert to embed link and converted link will be used inside a iframe. I don't know why its not working.

YouTube converter code (I'm trying to use any of these: Link to Embed)

function convertYoutube($string) {
    return preg_replace(
        "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
        "<iframe src=\"//www.youtube.com/embed/$2\" allowfullscreen></iframe>",
        $string
    );
}

String that receive YouTube link from SQL

$row["link"]
  • 写回答

1条回答 默认 最新

  • duandun2136 2016-11-29 00:22
    关注

    If you execute this, you will see the embeded youtube video. The $object is the embeded youtube url.

    <?php 
    $url = "https://www.youtube.com/watch?v=RboEKl7GgU0";
    parse_str( parse_url( $url, PHP_URL_QUERY ), $v );
    $object = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'.$v['v'].'" frameborder="0" allowfullscreen></iframe>';
    echo $object;
    ?>
    

    Instead of the $url you can obviously just use your $row['link']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记