我将以下代码存储在字符串中。
<ol class="tracklist">
<li class="track" data-file="https://www48.zippyshare.com/music/BCFNtvU9/0/file.mp3" data-index="0">
<a class="title name" href="#"><span class="name">1. MI Abaga - Do you know who you are_ Take some time and meditate on you</span></a>
<ul class="actions">
<li>
<a href=https://www41.zippyshare.com/v/BCFNtvU9/file.html" target="_blank"><span class="fa fa-arrow-down mobile-only-ib"></span>
<span class="text desktop-only-ib">Download</span></a>
</li>
</ul>
</li>
<li class="track" data-file="https://www41.zippyshare.com/music/FLCe2uFJ/0/file.mp3" data-index="1">
<a class="title name" href="#"><span class="name">2. MI Abaga - Last Night I Had A Dream About A Hummingbird</span></a>
<ul class="actions">
<li>
<a href="https://www41.zippyshare.com/v/FLCe2uFJ/file.html" target="_blank"><span class="fa fa-arrow-down mobile-only-ib"></span>
<span class="text desktop-only-ib">Download</span></a>
</li>
</ul>
</li>
</ol>
此示例的字符串将被称为$audio
,该字符串包含上述数据,我试图删除包含https://wwwRANDOMNUMBER.zippyshare.com/v/RANDOM-ID/file.html
的部分,然后对它们使用base64_encode以编程方式对用户隐藏所有文件链接,直到用户单击为止。
如何使用编码版本替换现有内容?
答案 0 :(得分:0)
这不能回答您的(暗示)第二个问题,即用户单击后如何解码base64。但是首先要对它们进行编码:
preg_match_all('#(https://www\d+.zippyshare\.com/(?:[^"]+))#',$audio, $matches);
foreach ( $matches as $match )
{
$encoded = base64_encode($match[1]);
$audio = str_replace($match[1], $encoded, $audio);
}