使用php将Audiomack播放器嵌入网站
我使用以下预匹配使用php将Audiomack播放器嵌入网站,php,preg-match,embed,Php,Preg Match,Embed,我使用以下预匹配 if (preg_match('![?&]{1}v=([^&]+)!', 'youtubeurl' . '&', $m)) $video_id = $m[1]; 要获取youtubeV值,请将其存储在$video\u id中,然后将其添加到iframe中 <iframe width="100%" height="305" src="http://www.youtube.com/embed/<? echo $video_id; ?>?r
if (preg_match('![?&]{1}v=([^&]+)!', 'youtubeurl' . '&', $m)) $video_id = $m[1];
要获取youtubeV值,请将其存储在$video\u id中,然后将其添加到iframe中
<iframe width="100%" height="305" src="http://www.youtube.com/embed/<? echo $video_id; ?>?rel=2&autoplay=0" frameborder="0" allowfullscreen></iframe>
它们的iframe如下所示
<iframe src="https://www.audiomack.com/embed4/famous-dex/annoyed" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>
$audio\u id的值应该返回著名的dex/happer
然后我可以将其插入iframe中
<iframe src="https://www.audiomack.com/embed4/<? echo $audio_id; ?>" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>
使用以下代码:
$url = 'https://www.audiomack.com/embed4/famous-dex/annoyed';
if (preg_match('/.+\/(.+\/.+)$/', $url, $matches)) {
$audio_id = $matches[1];
echo $audio_id; // gives you famous-dex/annoyed
}
匹配任何其他内容,直到达到“/”
捕获由“/”分隔的任意两个字符、单词等
结束匹配搜索
如果没有“$”,搜索将失败,因为在这种情况下,它会迫使搜索“从结尾开始,向后进行”。在您的答案中添加一个小的解释,解释它的工作原理。我刚刚添加了它。非常感谢@Morgoth。
<iframe src="https://www.audiomack.com/embed4/<? echo $audio_id; ?>" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>
$url = 'https://www.audiomack.com/embed4/famous-dex/annoyed';
if (preg_match('/.+\/(.+\/.+)$/', $url, $matches)) {
$audio_id = $matches[1];
echo $audio_id; // gives you famous-dex/annoyed
}