I want to display videos on my website. In file I have urls (separator | ) I can't do this: Do array from text in .txt. Get 4 random urls from array.
youtube_vids.txt
https://www.youtube.com/embed?v=oavMtUWDBTM|
https://www.youtube.com/embed?v=dQw4w9WgXcQ|
https://www.youtube.com/embed?v=djV11xsamQ|
https://www.youtube.com/embed?v=Tj75ArXbc914|
https://www.youtube.com/embed?v=9jK-NcRmVcw|
https://www.youtube.com/embed?v=n4RjJKhq5ho|
https://www.youtube.com/embed?v=6Ejga4kJUts|
I stopped here:
$vid_list = file('youtube_vids.txt');
Can anyone help me? Thanks a lot!
$videoArray = file('youtube_vids.txt');
$randomIndexes = array_rand($videoArray, 4);
foreach ($randomIndexes as $index) {
echo '<iframe width="420" height="315" src="'.preg_replace( "/\r|\n/", "", str_replace('|','',$videoArray[$index])).'"></iframe>';
}
will output
<iframe width="420" height="315" src="https://www.youtube.com/embed?v=dQw4w9WgXcQ"></iframe>
<iframe width="420" height="315" src="https://www.youtube.com/embed?v=oavMtUWDBTM"></iframe>
<iframe width="420" height="315" src="https://www.youtube.com/embed?v=6Ejga4kJUts"></iframe>
<iframe width="420" height="315" src="https://www.youtube.com/embed?v=dQw4w9WgXcQ"></iframe>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With