使用 php 将 Audiomack Player 嵌入网站
Embedding Audiomack Player onto website using php
我使用以下 preg 匹配
if (preg_match('![?&]{1}v=([^&]+)!', 'youtubeurl' . '&', $m)) $video_id = $m[1];
要获取 youtube V 值,请将其存储在 $video_id 中,然后将其添加到 iframe 中;
<iframe width="100%" height="305" src="http://www.youtube.com/embed/<? echo $video_id; ?>?rel=2&autoplay=0" frameborder="0" allowfullscreen></iframe>
在我的网站上加载 YouTube 视频。我正在尝试对 Audiomack 使用相同的方法,但它们的 URL 格式不同。
Audiomack 使用以下 URL 格式;
https://www.audiomack.com/song/famous-dex/annoyed
而他们的iframe如下;
<iframe src="https://www.audiomack.com/embed/song/famous-dex/annoyed" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>
如何修改上面的 preg_match 来获取 URL 的最后两个字符串连同斜杠,将其存储在一个变量中,然后然后从 iframe 调用它?
例如
$url = 'https://www.audiomack.com/famous-dex/song/annoyed';
if (preg_match('![?&]{1}v=([^&]+)!', '$url' . '&', $m)) $audio_id = $m[1];
和 $audio_id 的值应该 return song/famous-dex/annoyed
然后我可以将它插入到 iframe 中;
<iframe src="https://www.audiomack.com/embed/<? 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
}
- 匹配其他任何内容,直到到达“/”
- 捕获由“/”分隔的任意两个字符、单词等
- 结束匹配搜索。
如果没有“$”,搜索将失败,因为在这种情况下,它会强制搜索 "start from the end, backwards"。
我使用以下 preg 匹配
if (preg_match('![?&]{1}v=([^&]+)!', 'youtubeurl' . '&', $m)) $video_id = $m[1];
要获取 youtube V 值,请将其存储在 $video_id 中,然后将其添加到 iframe 中;
<iframe width="100%" height="305" src="http://www.youtube.com/embed/<? echo $video_id; ?>?rel=2&autoplay=0" frameborder="0" allowfullscreen></iframe>
在我的网站上加载 YouTube 视频。我正在尝试对 Audiomack 使用相同的方法,但它们的 URL 格式不同。
Audiomack 使用以下 URL 格式;
https://www.audiomack.com/song/famous-dex/annoyed
而他们的iframe如下;
<iframe src="https://www.audiomack.com/embed/song/famous-dex/annoyed" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>
如何修改上面的 preg_match 来获取 URL 的最后两个字符串连同斜杠,将其存储在一个变量中,然后然后从 iframe 调用它?
例如
$url = 'https://www.audiomack.com/famous-dex/song/annoyed';
if (preg_match('![?&]{1}v=([^&]+)!', '$url' . '&', $m)) $audio_id = $m[1];
和 $audio_id 的值应该 return song/famous-dex/annoyed 然后我可以将它插入到 iframe 中;
<iframe src="https://www.audiomack.com/embed/<? 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
}
- 匹配其他任何内容,直到到达“/”
- 捕获由“/”分隔的任意两个字符、单词等
- 结束匹配搜索。
如果没有“$”,搜索将失败,因为在这种情况下,它会强制搜索 "start from the end, backwards"。