如何使用PHP检测并替换带有iframe的文本中的soundcloud网址:
例如:
这:
https://soundcloud.com/aathmigan/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&color=00aabb&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
答案 0 :(得分:0)
我不确定我是否理解正确,但是这样的事情?
<?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>
答案 1 :(得分:0)
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&color=00aabb&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>',
$text);
return $text;
}
适合我。