dsifjgogw48491752
dsifjgogw48491752
2015-03-07 17:41
浏览 70
已采纳

如何将soundcloud url替换为iFrame(PHP)

How can I detect and replace a soundcloud url in a text with an iframe using PHP:

For example:

This:

https://soundcloud.com/aathmigan/eminem-ft-dr-dre-old-time-sake

Into this:

<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/140068709&amp;color=00aabb&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false"></iframe>

图片转代码服务由CSDN问答提供 功能建议

如何使用PHP检测和替换带有iframe的文本中的soundcloud网址:

例如:

这:

  https://soundcloud.com/aathmigan/eminem-ft-dr  -dre-old-time-sake 
   
 
 

进入:

 &lt; iframe width =“100%  “height =”166“scrolling =”no“frameborder =”no“src =”https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/140068709&amp  ;颜色= 00aabb&放大器;放大器; auto_play =假放大器;放大器; hide_related =假放大器;放大器; show_comments =真放大器;放大器; show_user =真放大器;放大器; show_reposts =假“&GT;&LT; / iframe中&GT; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dslijian2015
    dslijian2015 2017-02-05 09:40
    已采纳
      function linkifySoundcloudURLs( $text )
      {
        $text = preg_replace('#https{0,1}:\/\/w{0,3}\.*soundcloud\.com\/([^< ]+)#ix',
        '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https://soundcloud.com/$1&amp;color=00aabb&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false"></iframe>',
          $text);
        return $text;
      }
    

    Works for me.

    点赞 评论
  • dongwei8729
    dongwei8729 2015-03-07 17:44

    I'm not sure I understand you correctly, but something like this?

    <?php
      $url = "https://soundcloud.com/aathmigan/eminem-ft-dr-dre-old-time-sake";
    ?>    
    
    <iframe width="100%" height="166" scrolling="no" frameborder="no"
        src="<?php echo $url; ?>"></iframe>
    
    点赞 评论

相关推荐