kvishnu_13 Posted July 10, 2007 Share Posted July 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 10, 2007 Share Posted July 10, 2007 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 ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 10, 2007 Share Posted July 10, 2007 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; } ?> Quote Link to comment Share on other sites More sharing options...
kvishnu_13 Posted July 10, 2007 Author Share Posted July 10, 2007 thanks a lot cooldude...it's working!! i couldn't understand wat u did in the beginning, but now, after it makes sense, i've got to admit that that was pretty smart...lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.