Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting

getResponse autofunnels

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Information website that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,195 questions

16,607 answers

573 users

How to get the web page title tag content in PHP

1 Answer

0 votes
function get_html($url) {
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_HTTPGET, true);
    curl_setopt($handle, CURLOPT_HEADER, true);
    curl_setopt($handle, CURLOPT_URL, $url);
    curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($handle);
    $separator = "\r\n\r\n";
    $header = substr($output, 0, strpos($output, $separator));
    $body_start = strlen($header) + strlen($separator);
    $html = substr($output, $body_start, strlen($output) - $body_start);
    return $html;
$url = "https://www.webshopy.com"; 
$html = get_html($url);

$doc = new DOMDocument();

$titleTags = $doc->getElementsByTagName('title');
$title = $titleTags[0]->nodeValue;
echo $title;
WebShopy - Search! before you buy to find deals, coupons, sales & discounts


answered Sep 13, 2019 by avibootz