What is the most efficient way to retrieve the page title using cURL in PHP?

When using cURL in PHP to retrieve a webpage, you can efficiently extract the page title by using regular expressions to match the <title> tag in the HTML response. This allows you to quickly extract the title without parsing the entire HTML document.

&lt;?php
$url = &quot;https://example.com&quot;;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if(curl_errno($ch)){
    echo &#039;Error: &#039; . curl_error($ch);
}

curl_close($ch);

if(preg_match(&quot;/&lt;title&gt;(.*?)&lt;\/title&gt;/i&quot;, $response, $matches)){
    $title = $matches[1];
    echo &quot;Page title: &quot; . $title;
} else {
    echo &quot;Title not found&quot;;
}
?&gt;