-1

I have a array exp :

Array
(
    [0] => https://openload.co/f/duLIXdarHEM/RARBG.txt
    [1] => https://openload.co/f/C7D4l55xXn8/the.predator.2018.1080p.bluray.x264-sparks.idx
    [2] => https://openload.co/f/9fap6xaoJjQ/the.predator.2018.1080p.bluray.x264-sparks.sub
    [3] => https://openload.co/f/zE7ztog0j9U/the.predator.2018.1080p.bluray.x264-sparks.jpg
    [4] => https://openload.co/f/wjF657ljkVg/the.predator.2018.1080p.bluray.x264-sparks.mkv.mp4
    [5] => https://openload.co/f/4B0qD5ab5bU/Payback.Straight.Up.2006.DC.BRRip.XviD.MP3-XVID.avi
    [6] => https://openload.co/f/4B0qD5ab5bU/Payback.Straight.Up.2006.DC.BRRip.sample.XviD.MP3-XVID.avi
    [7] => https://openload.co/f/b1ihEIUgdDA/2_Eng.srt
)

How can I create a function to get links containing ".mp4", ".avi", ".mkv", ... and delete the links that contain the words ".txt" ".jpg" ".sample", ..... and bring it back to a new continuous array

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Not recommended to use smilies in the questions. – Udara Seneviratne Dec 14 '18 at 03:32
  • loop thru it, check the link with a regex and if it matches then add link to new array, keep new array when done. this isn't a code writing service - we'll help you fix the code that you wrote... – ivanivan Dec 14 '18 at 03:36
  • Possible duplicate of [How to remove all PHP array elements containing a certain sub-string?](https://stackoverflow.com/questions/10474216/how-to-remove-all-php-array-elements-containing-a-certain-sub-string) – musafar006 Dec 14 '18 at 03:54

3 Answers3

0

Try this:

$a=['https://openload.co/f/duLIXdarHEM/RARBG.txt','https://openload.co/f/b1ihEIUgdDA/2_Eng.srt','https://openload.co/f/4B0qD5ab5bU/Payback.Straight.Up.2006.DC.BRRip.XviD.MP3-XVID.avi'];

$b = array_filter($a, function($v){return preg_match("/(\.mp4){1}|(\.avi){1}|(\.mkv){1}/", $v);});

var_dump($b);

You can run check the result here

bachlee89
  • 717
  • 4
  • 8
0

Using strpos:

$array = ['https://openload.co/f/duLIXdarHEM/RARBG.txt',
          'https://openload.co/f/C7D4l55xXn8/the.predator.2018.1080p.bluray.x264-sparks.idx', 
          'https://openload.co/f/9fap6xaoJjQ/the.predator.2018.1080p.bluray.x264-sparks.sub', 
          'https://openload.co/f/zE7ztog0j9U/the.predator.2018.1080p.bluray.x264-sparks.jpg', 
          'https://openload.co/f/wjF657ljkVg/the.predator.2018.1080p.bluray.x264-sparks.mkv.mp4'];  

$result = array_filter($array, function($x) {     
    return (strpos($x, '.avi') || strpos($x, '.mp4') || strpos($x, '.mkv'));    
});  
print_r($result);  

Hope this helps!

Revathi Ganesh
  • 119
  • 1
  • 6
0

since you are going to bring the needed links back to another array anyway, why dont you just delete the not needed links from the original array and reindex it, you can accomplish that by:

`<?php
$array = array( 
"https://openload.co/f/duLIXdarHEM/RARBG.txt",  
"https://openload.co/f/C7D4l55xXn8/the.predator.2018.1080p.bluray.x264-sparks.idx", 
"https://openload.co/f/9fap6xaoJjQ/the.predator.2018.1080p.bluray.x264-sparks.sub", 
"https://openload.co/f/zE7ztog0j9U/the.predator.2018.1080p.bluray.x264-sparks.jpg",      
"https://openload.co/f/wjF657ljkVg/the.predator.2018.1080p.bluray.x264- 
 sparks.mkv.mp4",  
"https://openload.co/f/4B0qD5ab5bU/Payback.Straight.Up.2006.DC.BRRip.XviD.MP3- 
 XVID.avi",
"https://openload.co/f/4B0qD5ab5bU/Payback.Straight.Up.2006.DC.BRRip.sample.XviD.MP3- 
 XVID.avi", 
"https://openload.co/f/b1ihEIUgdDA/2_Eng.srt" );

foreach( $array as $arr ){
if(preg_match('/^.*\.(jpg|txt|sample|)$/i', $arr)){
unset($array[array_search($arr, $array)]);// delete the element
$newArray = array_values($array);// reindex array
}
}

print_r($newArray);`

you can see it in action here

rs007
  • 405
  • 4
  • 8