Get Title From HTML File

This little snippet will show you how to get string contain the title of an HTML file that located between and tag.

First, create a string containing the HTML file:

< ?php $a = fopen("html_file.html","r"); $string = fread($a,1024); ?>

Why we just read 1024 bytes? Because the &lt;title&gt; tag mostly located at the top part, which is covered by first 1024 byte. Well, actually it’s up to you how many byte you will read. :p

Then simply filter the string using eregi() function. We use eregi() so it will filter both TITLE and title tag (case insensitive).

< ?php // get text inbetween and tag.<br /> if (eregi("<title>(.*)", $string, $out)) {
$outdata = $out[1];

// display it
echo $outdata.

Happy coding! ^_*


  1. Dengan begitu title tiap halaman bisa sama ya? bukannya malah lebih baik title itu spesifik tiap halaman.

    Script ini untuk ngambil title dari suatu file HTML kok, bukan untuk masang title yg sama ^_*

  2. yap, itu ngambil diantara kok mas andi.

    Saya sendiri malah kaget liat iklannya.. “Gay Wedding Rings” ? haha
    *banner mencerminkan pemilik website*

    enak sajah! sayah normal! bukan ependiers!!

  3. ask

    It’s remarkable in favor of me to have a site,
    which is valuable designed for my knowledge. thanks admin

Leave a Reply