gerkintrigg Posted June 22, 2009 Share Posted June 22, 2009 Hello. I want to get the page title from the page that hosts a PHP script. So if the script runs on index.php, I want the title of index.php to be output. I have a script that appears to do this, but it's just not working properly. $my_page=curPageURL(); $filesource = $my_page; $a = fopen($filesource,"r"); //fopen("html_file.html","r"); $string = fread($a,1024); ?> <?php if (eregi("<title>(.*)</title>", $string, $out)) { $outdata = $out[1]; } echo $outdata; Link to comment https://forums.phpfreaks.com/topic/163262-getting-a-page-title/ Share on other sites More sharing options...
flyhoney Posted June 22, 2009 Share Posted June 22, 2009 <?php $contents = file_get_contents($my_page); if (preg_match('/<title>(.*)</title>/ig', $string, $matches)) { $outdata = $matches[1]; } echo $outdata; Link to comment https://forums.phpfreaks.com/topic/163262-getting-a-page-title/#findComment-861342 Share on other sites More sharing options...
flyhoney Posted June 22, 2009 Share Posted June 22, 2009 Ignore that last post, I actually tried this and it works <?php $my_page = curPageURL(); $contents = file_get_contents($my_page); if (preg_match('/<title>(.*)<\/title>/i', $contents, $matches)) { $outdata = $matches[1]; } echo $outdata; Link to comment https://forums.phpfreaks.com/topic/163262-getting-a-page-title/#findComment-861347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.