我正在爲我的網站編寫一個簡單的博客,並且我已成功完成此操作。使用PHP自動檢測並在HTML內容中嵌入MP4/MP3鏈接
function convertYoutube($string, $id='') {
return preg_replace(
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
"<div class=videoWrapper><iframe style=\"clear:both;\" width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/$2\" allowfullscreen></iframe></div>
",
$string
);
}
這是將youtube網址(短或長)轉換爲嵌入表單。
現在我希望做的是這樣的:
轉換的MP4鏈接,如:
http://cdn.example.com/akndh39/2016/askbdsjdbuu/my-video.mp4?id=28gsbd0mu&d=33hfsbb
到<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> </video>
轉換MP3鏈接到相應的代碼格式
不過,我不想鏈接轉換,如本
我希望他們保持不變一樣,對於MP4和MP3的鏈接。
編輯
我想是這樣的:
This is a very nice Video by Artiste So-n-So https://scontent.cdninstagram.com/t50.2886-16/13229628_1095069080586346_1424116369_n.mp4
<a href="http://cdn.example.com/akndh39/2016/askbdsjdbuu/my-video.mp4?id=28gsbd0mu&d=33hfsbb">
Download Video</a>
This is a very nice Video by Artiste So-n-So <video width="320" height="240" controls>
<source src="https://scontent.cdninstagram.com/t50.2886-16/13229628_1095069080586346_1424116369_n.mp4" type="video/mp4">
</video>
<a href="http://cdn.example.com/akndh39/2016/askbdsjdbuu/my-video.mp4?id=28gsbd0mu&d=33hfsbb">
Download Video</a>
請發佈**輸入**和所需**輸出**的清晰示例。 –
我編輯了問題 – Normal9ja
你會怎麼從* * to * Download Video *? –
sweaver2112