CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: HTML Title.

  1. #1
    Join Date
    May 2002
    Posts
    10,943

    HTML Title.

    I have searched and can't find it. Is there a way to specify a URL and have PHP read that pages TITLE tag?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Re: HTML Title.

    Hi peejavery,

    Sorry, I don't understand very well the question.

    As you know, the way to specify a URL is done either

    - by submitting a form whose action is to go to a specifed URL
    - by sendind a header containing a URL : header("Location: my_url.php")
    - by having an "href".

    About the title tag, as you know, it is a meta tag included in the <head> section of a page. PHP knows it, if PHP has dynamically created that page, or PHP can know it by reading that page like if it were an ordinary file, and searching for the keyword "title".

    Maybe, you wish that the title would appear, not only in the caption of the browser, but also in the URL field of the browser. This can be done if the server is configured to accept what is called "URL rewriting".

  3. #3
    Join Date
    May 2004
    Location
    MN / NJ, United States
    Posts
    768

    Re: HTML Title.

    I think he wnats to look at a website, such as http://codeguru.com from his server, and use PHP to grab the title of the page. Me in particular, I don't know a solution.
    *9-11-01* Never Forget; Never Forgive; Never Relent!
    "If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: HTML Title.

    Quote Originally Posted by Dr. Script
    I think he wnats to look at a website, such as http://codeguru.com from his server, and use PHP to grab the title of the page. Me in particular, I don't know a solution.
    Exactly.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2004
    Location
    Germany
    Posts
    655

    Re: HTML Title.

    ever heard of a function named file?
    file returns an array with all lines of the target file, which can also be an url.
    than you could iterate through that array an search for the title tag.

    another approach is to use file_get_contents.
    file_get_contents returns the whole content of the target file into one single string.

    Code:
    $sContent = file_get_contents('http://de3.php.net/manual/en/function.preg-match.php');
    
    if( preg_match( '/<title>(.*)<\/title>/mi', $sContent, $aMatches) ) {
        print_r($aMatches);
    }
    if all went well, $aMatches[1] contains the pages title (PHP: preg_match - Manual).
    Last edited by bigBA; September 5th, 2005 at 07:38 AM.
    there are 10 kinds of people. those who understand binary and those who don't...

    rate a post if you find it usefull, thx
    check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured