How to get website title in PHP

3 Answers

0 votes
$doc = new DOMDocument();
@$doc->loadHTMLFile('https://www.buyfrompictures.com');
$xpath = new DOMXPath($doc);

$title = $xpath->query('//title')->item(0)->nodeValue;

echo $title;




/*
run:

Buy From Pictures | See It, Like It?, Buy It 

*/

 



answered Feb 13, 2021 by avibootz
0 votes
function file_get_contents_curl($url)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

$html = file_get_contents_curl("https://www.keywordsandwebsites.com/");

$doc = new DOMDocument();
@$doc->loadHTML($html);
$title = $doc->getElementsByTagName('title');

echo $title->item(0)->nodeValue;




/*
run:

Keywords and Websites – Top quality websites for represented keyword

*/

 



answered Feb 13, 2021 by avibootz
0 votes
$handle = curl_init("https://www.keywordsandwebsites.com/");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$html = curl_exec($handle);
curl_close($handle);

$doc = new DOMDocument();
@$doc->loadHTML($html);
$title = $doc->getElementsByTagName('title');

echo $title->item(0)->nodeValue;





/*
run:

Keywords and Websites – Top quality websites for represented keyword

*/

 



answered Feb 13, 2021 by avibootz

Related questions

2 answers 196 views
2 answers 1,043 views
1 answer 387 views
1 answer 213 views
1 answer 177 views
177 views asked Sep 15, 2019 by avibootz
1 answer 163 views
...