In cURL requests, how are embedded images and scripts handled and retrieved?

When making cURL requests, embedded images and scripts are not automatically retrieved by default. To handle embedded images and scripts, you can parse the HTML content of the response and extract the URLs of the images and scripts. You can then make additional cURL requests to retrieve these resources separately.

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL request
$response = curl_exec($ch);

// Close cURL session
curl_close($ch);

// Parse HTML content to extract image and script URLs
preg_match_all('/<img[^>]+src="([^">]+)"/', $response, $imageUrls);
preg_match_all('/<script[^>]+src="([^">]+)"/', $response, $scriptUrls);

// Retrieve images and scripts separately
foreach($imageUrls[1] as $imageUrl) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $imageUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $imageResponse = curl_exec($ch);
    curl_close($ch);
    // Handle image response
}

foreach($scriptUrls[1] as $scriptUrl) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $scriptUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $scriptResponse = curl_exec($ch);
    curl_close($ch);
    // Handle script response
}