What are the differences between accessing a URL in a browser versus using wget or curl in the command line for PHP?

When accessing a URL in a browser, the response is rendered in the browser window, while using wget or curl in the command line allows you to retrieve the content of the URL programmatically without rendering it in a browser. To achieve this in PHP, you can use the curl library to make HTTP requests and retrieve the content of a URL.

<?php

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

// Set the URL to retrieve
curl_setopt($ch, CURLOPT_URL, "http://example.com");

// Set the option to return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Execute the cURL session
$response = curl_exec($ch);

// Close cURL session
curl_close($ch);

// Output the response
echo $response;

?>