Jump to content

[SOLVED] Accessing a website's title


kvishnu_13

Recommended Posts

Hey,

Is there any way we can access the title of a web page through php?

This is how I want it work:

1. User inputs webpage address in a form.

2. My website should display the title of the inputted website(as in, 'www.google.com' has a title of 'Google - Home').

 

Any ideas?

 

Help will be greatly appreciated guys...been lingering around a lot for a solution

___

kvishnu_13

Link to comment
Share on other sites

this would be a tad bit over kill but try

<?php
if($content=file_get_contents($url)){
$title_start = strpos($content,"<title>")-1;
$title_length = strpos($content,"</title>")-$title_start;
$title = str_replace("</title>","",str_replace("<title>","",substr($content,$title_start,$title_length),1)); //This should be the title
?>

Link to comment
Share on other sites

tested this out and it works:

<?php
$url = $_GET['URL'];
if($content=file_get_contents($url)){
$title_start = strpos($content,"<title>");
$title_length = strpos($content,"</title>")-$title_start;
$title = substr($content,$title_start,$title_length); //This should be the title
$title = str_replace("</title>","",$title);
$title = str_replace("<title>","",$title);
echo $title;
}
?>

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.