Jump to content

Get Title Code Problem if php in title (preg_match)


munnaz

Recommended Posts

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!

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

 

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.