munnaz Posted June 26, 2011 Share Posted June 26, 2011 Hey guys, I have the following code: <? $url = "../index.php"; $file = file($url); $file = implode("",$file); if(preg_match("/<title>(.*)<\/title>/",$file,$m)) print "The title of $url is <b>$m[1]</b>"; else print "The page doesn't have a title tag"; ?> My page title on the index page is: <title>Home | <?php include("include/pagetitle.php") ?></title> But my problem is that i have <?php include("include/pagetitle.php") ?> in my title and it is not pulling that code from the include page. It just prints ''Home |'' Can anyone help? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/240413-get-title-code-problem-if-php-in-title-preg_match/ Share on other sites More sharing options...
dragon_sa Posted June 26, 2011 Share Posted June 26, 2011 your missing a semi colon <title>Home | <?php include("include/pagetitle.php") ?></title> should be <title>Home | <?php include("include/pagetitle.php"); ?></title> if that doesnt fix your issue check the path to your file that the names are spelled correctly. I cant see where $m is defined in that code either Quote Link to comment https://forums.phpfreaks.com/topic/240413-get-title-code-problem-if-php-in-title-preg_match/#findComment-1234898 Share on other sites More sharing options...
munnaz Posted June 26, 2011 Author Share Posted June 26, 2011 your missing a semi colon. if that doesnt fix your issue check the path to your file that the names are spelled correctly. I cant see where $m is defined in that code either $m is defined: preg_match("/<title>(.*)<\/title>/",$file,$m)) Description: int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) semi colon doesn't change anything and path is correct. The title is clearly displayed at the top of the webpage brower when I visit it but it does not show up when I use the php code mentioned above. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/240413-get-title-code-problem-if-php-in-title-preg_match/#findComment-1234905 Share on other sites More sharing options...
dreamwest Posted June 26, 2011 Share Posted June 26, 2011 <?php $string = file_get_contents("http://site.com/index.php"); if(preg_match('~<title>(.*)</title>~is', $string, $m)){ print "The title of $url is <b>{$m[1]}</b>"; }else{ print "The page doesn't have a title tag"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240413-get-title-code-problem-if-php-in-title-preg_match/#findComment-1234915 Share on other sites More sharing options...
munnaz Posted June 27, 2011 Author Share Posted June 27, 2011 Thanks for reply. That output still just prints 'Home | ' Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/240413-get-title-code-problem-if-php-in-title-preg_match/#findComment-1235198 Share on other sites More sharing options...
munnaz Posted June 27, 2011 Author Share Posted June 27, 2011 or if i could just remove the last three digits off it? ' | ' So it would just print 'Home'? Quote Link to comment https://forums.phpfreaks.com/topic/240413-get-title-code-problem-if-php-in-title-preg_match/#findComment-1235200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.