Laravel Türkiye Discord Kanalı Forumda kod paylaşılırken dikkat edilmesi gerekenler!Birlikte proje geliştirmek ister misiniz?

Rss saysasında
foreach ($feed->channel->item as $article) {

sonrasında
$img = $article->description;
if (preg_match( '|<img.?src=\'"[\'"].?>|i', $img, $matches)) {
ile resimleri alıyorum ama resimler her zaman item içinde olsada description içinde olmuyor. php children() fonksiyonunu kullanmaya çalışıyorum ama $img = $article->children(); ama işe yaramıyor.

ayrıca xpath da denedim
$feed = simplexml_load_string($response->body());
$img = $feed->xpath('//item');
buda işe yaramadı.

    aeneas //img[@src] size src değeri olan tüm resimleri verir. /div[@id='content']//img[@src] size id'si content olan div'in içindeki tüm resimleri verir.

    @mgsmus hocam sorun şu
    $feed = simplexml_load_string($response->Body()); bana aşağıdakini verir

    14 => SimpleXMLElement {#955
    +"title": SimpleXMLElement {#1039}
    +"category": SimpleXMLElement {#1040}
    +"link": "https://webrazzi.com/2023/10/16/apple-bu-hafta-yenilenmis-ipadleri-duyurabilir/"
    +"comments": "https://webrazzi.com/2023/10/16/apple-bu-hafta-yenilenmis-ipadleri-duyurabilir/#comments"
    +"description": SimpleXMLElement {#1041}
    +"guid": "https://webrazzi.com/2023/10/16/apple-bu-hafta-yenilenmis-ipadleri-duyurabilir/"
    +"pubDate": "Mon, 16 Oct 2023 09:00:00 +0000"

    oysa resim bir p tagı içinde ama simplexml_load_string bana html tag larını vermıyor. $response->Body() bana tüm sayfayı veriyor aslında.

    <p><img class="lazyload aligncenter" title="pipifier-673" data-src="https://cdn.webrazzi.com/uploads/2023/10/pipifier-673.png" alt="" width="714" height="402" /></p>

    resimler description içinde değilse yakalamak çok zor çünkü çok farklı taglar içinde olabiliyor.

      aeneas

      libxml_use_internal_errors(true);
      
      $dom = new DOMDocument();
      $dom->load('https://webrazzi.com/feed/', LIBXML_NOCDATA);
      $xpath = new DOMXPath($dom);
      
      $descriptions = $xpath->query('//item/description');
      $contents = $xpath->query('//item/content:encoded');
      
      $html = "";
      
      foreach($descriptions as $node) {
          if($node && $node->nodeValue) {
              $html .= $node->nodeValue;
          }
      }
      
      foreach($contents as $node) {
          if($node && $node->nodeValue) {
              $html .= $node->nodeValue;
          }
      }
      
      $dom = new DOMDocument();
      $dom->loadHTML($html);
      $xpath = new DOMXPath($dom);
      
      $images = $xpath->query('//img');
      
      $srcList = [];
      
      foreach($images as $node) {
          if($node) {
              $src = $node->getAttribute('data-src') ?? $node->getAttribute('src');
      
              if($src) {
                  $srcList[] = $src;
              }
          }
      }
      
      return $srcList;
      [
        "https://cdn.webrazzi.com/uploads/2023/10/pipifier-673.png",
        "https://cdn.webrazzi.com/uploads/2023/10/stopper-kapak-50.png",
        "https://cdn.webrazzi.com/uploads/2023/10/duckduckgo-desktop-app-669.jpg",
        "https://cdn.webrazzi.com/uploads/2023/10/ekran-resmi-2023-10-23-144919-39.png",
        "https://cdn.webrazzi.com/uploads/2023/10/screen-shot-2021-09-20-at-14450-pm-597.png",
        "https://cdn.webrazzi.com/uploads/2023/10/643x0w-929.jpg",
        "https://cdn.webrazzi.com/sponsors/2023/10/275x120-29-1697817421903.jpg",
        "https://cdn.webrazzi.com/uploads/2023/10/open-972.jpg",
        "https://cdn.webrazzi.com/uploads/2023/10/performance-marti-133.png",
        "https://cdn.webrazzi.com/uploads/2023/10/marti-38.png",
        "https://cdn.webrazzi.com/uploads/2023/10/marti-2-216.png",
        "https://cdn.webrazzi.com/uploads/2023/10/tag-drivers-954.png",
        "https://cdn.webrazzi.com/uploads/2023/10/marti-e-moped-878.png",
        "https://cdn.webrazzi.com/uploads/2023/10/marti-gelir-87.png",
        "https://cdn.webrazzi.com/uploads/2023/10/marti-kar-zar-907.png",
        "https://cdn.webrazzi.com/sponsors/2023/10/275x120-29-1697817421903.jpg",
        "https://cdn.webrazzi.com/uploads/2023/10/open-972.jpg",
        "https://cdn.webrazzi.com/uploads/2023/10/drill-and-collect-apps-920.png",
        "https://cdn.webrazzi.com/uploads/2023/10/apps-google-979.png",
        "https://cdn.webrazzi.com/uploads/2023/10/ekran-resmi-2023-10-20-093105-378.png",
        "https://cdn.webrazzi.com/uploads/2023/10/dall-e-3-434.png"
      ]

      Ayrıca bu işler için Symfony DomCrawler da kullanabilirsiniz:
      https://symfony.com/doc/current/components/dom_crawler.html