Kamlesh Singh
Kamlesh Singh

Reputation: 3

How to get meta tags of current webpage using PHP?

I created following meta tags in head

<meta name="image" content="image url" />
<meta name="title" content="Page title" />

Now I used following code to extract URL and then the tags

$url='http://' .$_SERVER[ 'HTTP_HOST'].$_SERVER[ 'REQUEST_URI'];
$tags = get_meta_tags($url); 
$image = $tags['image'];
$title = $tags['title'];

The page however keeps loading and outputs nothing.

Upvotes: 0

Views: 1387

Answers (2)

stdob--
stdob--

Reputation: 29172

It's look like you call get_meta_tags script itself? If yes, you get infinite recursion and output nothing. Page keep loadings, and in the end, of course, would be a mistake - exceeded the maximum execution time.

Upvotes: 0

Matt Komarnicki
Matt Komarnicki

Reputation: 5422

How do you expect to see something if you're just assigning a variable and nothing else?

Do var_dump($image) and then for example die() to see it's content... or whatever you need.

Upvotes: 1

Related Questions