1 2 3 4 5 6 7 8 9 10 11 12
<?php function get_title($html_page) { // split the page into 3 sections, with the <title> and </title> tags as delimiters. $split_page = preg_split("%</?title[^>]*>%",$html_page); if (sizeof($split_page) == 3) return $split_page[1]; else return "No title"; } ?>
Refactorings
No refactoring yet !
Christoffer
February 9, 2010, February 09, 2010 16:49, permalink
1 2 3 4 5 6
<?php function get_title($html_page) { return preg_match('/<title>(.+?)</title>/i', $html_page, $match) ? $match[1] : 'No title'; } ?>
Extract and return the bits between the <title> and </title> tags of an html page.