You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find Images: The code then looks for tags within each found element.
$images = $xpath->query('.//img', $element): This line finds all elements within the current element and stores them in $images.
Iterate over Found Images: The loop iterates over each image found in the current element.
foreach ($images as $img): This starts another loop for each image found within the current element.
Extract and Validate Image URLs: The code extracts the URL from each image and checks whether it's a valid URL or a placeholder. If it's a placeholder, the code attempts to find a real image URL from alternative attributes commonly used with lazy-loaded images.
$src = $img->getAttribute('src'): This line gets the src attribute of the image.
If the src is a data URI or SVG (indicating a placeholder), the code checks other attributes like data-src, data-lazy-src, or data-original for an actual image URL.
Convert Relative URLs to Absolute: If a valid image URL is found and it's a relative URL, the code converts it to an absolute URL based on the page's domain.
$src = $this->convertToAbsoluteUrl($src, ...): This calls a method that converts a relative URL to an absolute one.
Store Unique URLs: Finally, if the image URL hasn't already been added to the $imageUrls array, the code adds it.
if (!in_array($src, $imageUrls)) { $imageUrls[] = $src; }: This checks if the URL is already in the array and, if not, adds it.