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
https://forums.phpfreaks.com/topic/59212-solved-accessing-a-websites-title/
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
?>

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;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.