All keys of array values ​​at [0] with simple html dom

I am trying to create a Mirror site for Anime

file_get_contents($page);

$html->load_file($page);

$links = array();

foreach($html->find('iframe') as $element) 
{
    $links[] = $element;    
}

foreach ($links as $out) 
{
$links = preg_match('/(http:\/\/mp4upload.com).+?(html)/', $out, $matches);
unset($matches[1]);
unset($matches[2]);
    if($matches){                               
        $mirror_link = $matches[0];

      

This is my current code, but every time I load it

The array is displayed as follows

Array ( [0] => LINK ) 
Array ( [0] => LINK  ) 
Array ( [0] => LINK  ) 
Array ( [0] => LINK )

      

Is it possible to limit this to only 1 link and remove the rest?

+3


source to share


1 answer


You should have break

your loop when you find what you are looking for:



$mirror_link = [];

foreach ($links as $out) {
    ...

    if ($matches) {                               
        $mirror_link = $matches[0];

        break; // <-- Will prevent loop form iterating further.
        //break(2) will break current and parent loop
    }
}

      

0


source







All Articles