I am using the following code to get the full html from a specified page:
$url = "http://www.google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close ($ch);
Question: how can this code be modified to return the <title>
instead of the full html of the page. $result stores the result.
You can get the title using regular expression, I find this regex very helpful:
function get_html_title($html){
preg_match("/\<title.*\>(.*)\<\/title\>/isU", $html, $matches);
return $matches[1];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With