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']

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度