[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Retreving Title of a page

using php how to retreive the title of a page
0
qader99
Asked:
qader99
  • 6
  • 3
1 Solution
 
us111Commented:
I think you can't do that
hmm..

you can find the title by reading the htmlfile and catch your title
by spliting <title> and </title>

0
 
qader99Author Commented:
can't clearly undestand what do you mean to say

please help with an example.
0
 
us111Commented:
Below a piece of code which gives you a title of a page
I don't think if it's the best solution but it works
You may optimize this function.....

<?
  // Open file
   $f = fopen("yourhtmlpage.html", "r");
   
   // read first line
   $line = fgets($f,2000);

   $found = false;
   while(!feof($f) && $found == false)
   {  
      // Put lowercase
      $myline = strtolower($line);
      if (strstr($myline,"<title>") <> false )
      {
         // Split string to get the title
         $title = split("<title>",$myline);
         $title = split("</title>", $title[1]);
         $title = $title[0];
         $found = true;
       }

       // Read next line
       $line = fgets($f,2000);
   }
   
   // Print title
   print ucfirst($title);
   fclose($f);
?>
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
qader99Author Commented:
Adjusted points to 20
0
 
qader99Author Commented:
Thank you very much the code is working
perfectly.

qader99
0
 
us111Commented:
don't forget to give me your points :))
thx
0
 
us111Commented:
Well
0
 
us111Commented:
Please could you accept my comment ? :))
0
 
us111Commented:
Hi qader99, could accept my comment as answer ?

Thanks you very much :))

us111.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now