Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to get the web page description tag content in PHP

2 Answers

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);
   
    curl_close($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.collectivesolver.com"; 
   
$html = get_html($url);

$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);

$metaTags = $doc->getElementsByTagName('meta');
foreach ($metaTags as $tag) {
	if ($tag->getAttribute('name') == 'description') {
            $description = $tag->getAttribute('content');
	}
}
   
echo $description;
   
   
/*
run:
   
Programming Q&A in Java, Python, PHP, C, C++, C#, JavaScript, MySQL, WinAPI, Win32, VB.NET...
   
*/

 





answered Sep 13, 2019 by avibootz
0 votes
$tags = get_meta_tags('https://www.collectivesolver.com');

$description = $tags['description'];
   
echo $description;
   
   
/*
run:
   
Programming Q&A in Java, Python, PHP, C, C++, C#, JavaScript, MySQL, WinAPI, Win32, VB.NET...
   
*/

 





answered Sep 13, 2019 by avibootz

Related questions

1 answer 91 views
1 answer 122 views
1 answer 75 views
75 views asked Sep 13, 2019 by avibootz
3 answers 166 views
...