Jump to content

Recommended Posts

I am working on a script at the moment and I am trying to read the title of the page (between <title> and </title> tags) I can't figure out how to do it in PHP so I was trying to use javascript since it is way easier. However I can't get it to work.

 

Heres the code:

$pagetitle = "<script language=javascript>document.title</script>";

 

I have tried chaning it (using " or ' around language=javascript) and I know that is the correct javascript because if you plug it into your brower as javascript:document.title it returns the title.

 

If anybody has figured this out before or if anybody knows how to do this (read the title) with PHP that would be great!

 

Thanks in advance!!

Jeffrey

$fh = fopen($DOCUMENT_ROOT.$PHP_SELF,"r");
$found=false;
$title="";
while(!feof($fh) && !found){
   if(preg_match("/<title>(.*)<\\\/title>/",fget($fh,4096),$matches)){
      $found=true;
      $title=$matches[1];
   }
}
fclose($fh);
if($found){
   // Here title is correct
}
else{
   // this page doesn't contain <title>
}

 

http://www.dmxzone.com/forum/topic.asp?topic_id=14764

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.