What is the issue with using fopen to access HTML content from another website in PHP?

Using fopen to access HTML content from another website in PHP can be problematic because it may not work due to security restrictions or the website may block external requests. An alternative approach is to use cURL, which is more robust and allows for better control over HTTP requests.

<?php
$url = 'https://www.example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);

echo $output;
?>