How can PHP be used to access and manipulate data from external sources?
To access and manipulate data from external sources using PHP, you can use various methods such as cURL, file_get_contents, or APIs. These methods allow you to retrieve data from external sources like websites, databases, or APIs, and then manipulate the data as needed within your PHP application.
// Using cURL to access and manipulate data from an external source
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.example.com/data');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
// Manipulate the data retrieved from the external source
if ($data) {
$parsed_data = json_decode($data, true);
// Perform manipulation on the parsed data
echo $parsed_data['key'];
}