Retrieving a title from a website

Discussion in 'PHP' started by blueparukia, Nov 14, 2007.

  1. #1
    Say I have a variable:

    $var1 = "http://google.com/"

    Now how could I retrieve the page title from that variable? (In this case "Google").

    Same goes if var1 was http://forums.digitalpoint.com, I need a way to retrieve "Internet Marketing and....whatever the rest of the title is"

    Thanks,

    BP
     
    blueparukia, Nov 14, 2007 IP
  2. tarponkeith

    tarponkeith Well-Known Member

    Messages:
    4,758
    Likes Received:
    279
    Best Answers:
    0
    Trophy Points:
    180
    #2
    That's a tall order... Are you paying for this project?

    If not, I'd suggest you look into wget :)
     
    tarponkeith, Nov 14, 2007 IP
  3. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #3
    I didnt realise it would be so hard :S system() is blocked by servers, and the only example I could get of wget was iwith using system()

    Thanks anyway,

    BP
     
    blueparukia, Nov 14, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    
    <?php
    $page = fopen('http://www.upload4ever.com','r');
    while($cont = fread($page,1025654)){
    	$info .= $cont;
    }
    fclose($page);
    /*
    Since you don't want to read the entire page,
    maybe this would be sufficent
    $info = fread($page,1025654);
    But this will only pick up the first 1025654 bytes
    */
    
    preg_match('/<title>(.*)<\/title>/Uis',$info,$results);
    $page_title = $results[1];
    ?>
    
    PHP:
    Don't have time to test it, but it should work.

    Peace,
     
    Barti1987, Nov 14, 2007 IP
    blueparukia likes this.
  5. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #5
    Yes it works :D :D

    Thank you very much :D
     
    blueparukia, Nov 14, 2007 IP
  6. lawrenz

    lawrenz Peon

    Messages:
    246
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    id your site is dynamic your can make the title of your site dynamic. =)
     
    lawrenz, Mar 24, 2008 IP
  7. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Lawrenz please stop replying to very old threads.
     
    matthewrobertbell, Mar 26, 2008 IP