dsadsa123111 2012-04-27 16:23
浏览 65

嵌入youtube视频参数被忽略

I use the following code to replace youtube urls to embed links in order to display them as videos. But I have come to a problem where I can't view videos from links having more parameters other than ?v=video_code

php code:

function embedYoutube($text)
{

    $pattern = '|http://www\.youtube\.com/watch\?.*?\bv=([^ ]+)|';
    $replacement = '<div style="width:100%;float:left;margin-top:15px;margin-bottom:15px;"><iframe width="570" height="315" src=http://www.youtube.com/embed/$1 frameborder="0" allowfullscreen></iframe></div>';
    return preg_replace($pattern, $replacement, $text, 1);

}
  • 写回答

1条回答 默认 最新

  • dsm13698679318 2012-04-27 16:30
    关注

    Update your regex to match only the v parameter, and before the first &:

    |http://www\.youtube\.com/watch\?.*?\bv=([^ ]+)\&?|
    
    评论

报告相同问题?

悬赏问题

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