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

How can I replace a soundcloud url to an iFrame (PHP)

如何使用 PHP:

检测文本中的 soundcloud url 并将其替换为 iframe

例如:

这个:

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

进入这个:

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

我不确定我是否理解正确,但是是这样的吗?

<?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>
  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/&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;
  }

适合我。