Jump to content

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?

<?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";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.