$url = "https://www.example.com"; $page_content = file_get_contents($url); echo $page_content;
$url = "https://api.example.com/data"; $data = file_get_contents($url); $json_data = json_decode($data); echo $json_data->name;In this example, the file_get_contents function is used to retrieve the JSON data from an API endpoint. The retrieved data is then decoded using the json_decode function and stored in the $json_data variable. The property "name" of the JSON object is then accessed and displayed using the echo statement. Package/Library: No package/library is required as this function is built-in to PHP. However, the json_decode function is part of the JSON extension which is enabled by default in most PHP installations.