Jump to content

get_meta_tags(): Can Not Connect to Server


The Little Guy

Recommended Posts

is $http an array? otherwise you might try this

$domain= $_POST["domain"];
$tags = @get_meta_tags("http://",$domain);

 

Besides your syntax being off I don't see what that has to do with the question.

 

Op: There is no way of distinguishing why the function failed, it will just return an empty array.

Link to comment
Share on other sites

I am using this:

 

$tags = @get_meta_tags($http["domain"]);

 

Is there any way to tell if that function can not connect to the server for reasons such as server being down, or an invalid URL?

 

by any chance, are you attempting to get meta tags from a secure site? (https)

Link to comment
Share on other sites

After deciding to do a var_dump, which I should have done before posting, it seems as if on a failed connection it returns false, and everything else it returns an array for.

 

That should have been in the documentation.

 

Another thing that would have been nice is if this supported an html string so I could use cURL on on it, but oh well.

Link to comment
Share on other sites

Another thing that would have been nice is if this supported an html string so I could use cURL on on it, but oh well.

 

Not following you here? Surely if you know the URL to get the tags, you can construct a cURL request instead?

Link to comment
Share on other sites

Not following you here? Surely if you know the URL to get the tags, you can construct a cURL request instead?

 

Currently all you can do is pass it a filename or a URL, it would be nice to be able to do this:

 

// perform a curl request here, and get the html string back as $html_string
// $html_string = "<html>
//	<head>
//		<title>Title</title>
//		<meta name="myMeta1" content="my content" />
//		<meta name="myMeta2" content="my content 2" />
//		<meta name="myMeta3" content="my content 3" />
//	</head>
//	<!-- rest of html -->
//</html>";


$tags = get_meta_tags($html_string);
var_dump($tags);

Link to comment
Share on other sites

Oh I see. Well you realise using SimpleXML you could probably parse out that information pretty easily right? Even a simple regex would do the trick.

 

SimpleXML doesn't work well on HTML files, especially if they have javascript/css written into the file.

 

Quite right. The DOM then:

 

$html = '<!DOCTYPE html>
<html>
    <head>
        <title>This is the title</title>
        <meta name="keywords" content="this is a self-closing tag" />
        <meta name="description" content="this is not a self-closing tag">
        <meta name=author content=idiot>
        <script>
            window.onload = function() {
                alert(\'here\\\'s some JavaScript..\');
            }
        </script>
    </head>
    <body>
    </body>
</html>';

$dom = new DOMDocument();
$dom->loadHTML($html);

foreach ($dom->getElementsByTagName('meta') as $meta) {
    echo 'Meta ' . $meta->getAttribute('name') . ' = ' . $meta->getAttribute('content') . '<br />';
}

 

Works even with some pretty badly written HTML.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.