What are some common functions used in PHP for retrieving data from external sources?

When retrieving data from external sources in PHP, some common functions used include file_get_contents() for fetching the contents of a file or URL, curl_init() and curl_exec() for making HTTP requests, and simplexml_load_file() for parsing XML data. These functions allow developers to easily access and manipulate data from various sources on the web.

// Using file_get_contents to retrieve data from a URL
$url = 'https://example.com/data.json';
$data = file_get_contents($url);

// Using cURL to make an HTTP request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com/api');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

// Using simplexml_load_file to parse XML data
$xml = simplexml_load_file('https://example.com/data.xml');