Detecting HTML Page Title in PHP

Discussion in 'PHP' started by ProductivePC, May 29, 2004.

  1. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #21
    Here you go, this should do the trick:

    <?php
    
    //replace this with the url of your page
    $html = file_get_contents('http://forums.digitalpoint.com/index.php');
    
    
    if(preg_match('/<title>(.*)<\/title>/smU', $html, $matches)) {
    
    $title = $matches[1];
    
    echo $title;
    
    } else {
    
    echo("Tite tag could'nt be found");
    
    }
    ?>
    PHP:
    Example output:

    Webmaster Forum - Internet Marketing & Search Engine Forums
    Code (markup):

     
    danx10, Jan 6, 2010 IP