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 tag.
First, create a string containing the HTML file:
$a = fopen("html_file.html","r");
$string = fread($a,1024);
?>
Why we just read 1024 bytes? Because the <title> 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).
// get text inbetween tag.
if (eregi(”“, $string, $out)) {
$outdata = $out[1];
}
// display it
echo $outdata.
?>
Happy coding! ^_*
November 18th, 2006 at 8:14 am
Dengan begitu title tiap halaman bisa sama ya? bukannya malah lebih baik title itu spesifik tiap halaman.
November 20th, 2006 at 2:47 pm
yap, itu ngambil diantara kok mas andi.
Saya sendiri malah kaget liat iklannya.. “Gay Wedding Rings” ? haha
*banner mencerminkan pemilik website*