2021年4月1日星期四

Undefined offset: 0 in PHP array (Laravel)

Its a simple code, I have this array :

array(1) { [0]=> array(2) { [0]=> string(85) "https://www.blog.google.com/wp-content/uploads/image.jpg" [1]=> int(40) } }

So I want to read the URL with PHP, I do this :

 echo $matches[0][0];  

I dont understand :

Undefined offset: 0 (View: /var/www/html/netparabox/resources/views/welcome.blade.php)  

Please, tell me what I did wrong ?

EDIT :

So Im in welcome.blade.php, it is the entiere code :

<?php    $rss = new DOMDocument();    $rss->load('http://www.blog.google.com/feed/');    $feed = array();    foreach ($rss->getElementsByTagName('item') as $node) {      $item = array (         'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,        );      array_push($feed, $item);    }    $limit = 2;    for($x=0;$x<$limit;$x++) {        // ajouter que si on a qu'un seul article par exemple ça bug of course      $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);      $link = $feed[$x]['link'];      $description = $feed[$x]['desc'];      $date = date('l F d, Y', strtotime($feed[$x]['date']));        preg_match('#(?:(?:https?)+\:\/\/+[a-zA-Z0-9\/\._-]{1,})+(?:(?:jpe?g|png|gif))#', $description, $matches, PREG_OFFSET_CAPTURE);    var_dump($matches);    echo $matches[0][0];              echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';      echo '<small><em>Posted on '.$date.'</em></small></p>';      echo '<p>'.$description.'</p>';        }  ?>  
https://stackoverflow.com/questions/66899842/undefined-offset-0-in-php-array-laravel April 01, 2021 at 03:03PM

没有评论:

发表评论