'Failed to fetch data from Google.']); } else { $imageUrls = extractImageUrlsFromPage($response); header('Content-Type: application/json'); echo json_encode(['imageUrls' => $imageUrls]); } } else { // Parse the HTML response to extract image URLs $imageUrls = extractImageUrlsFromPage($response); // Pass the image URLs to the client header('Content-Type: application/json'); echo json_encode(['imageUrls' => $imageUrls]); } curl_close($ch); } else { echo json_encode(['error' => 'Invalid request.']); } function extractImageUrlsFromPage($html) { $imageUrls = []; $doc = new DOMDocument(); @$doc->loadHTML($html); $imgTags = $doc->getElementsByTagName('img'); foreach ($imgTags as $imgTag) { $src = $imgTag->getAttribute('src'); if (!strstr($imgTag->getAttribute('class'), "favicon") && !strstr($imgTag->getAttribute('class'), "logo")) { if (filter_var($src, FILTER_VALIDATE_URL)) { $imageUrls[] = $src; } } } return $imageUrls; } ?>