Jump to content

Recommended Posts

I am getting confused. i ahve the following code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>State Search</title>
    <link href="../css/stylesheet.css" rel="stylesheet" type="text/css" />
</head>

    <body>
        <?php
		//includes the top header	
		print $pagetitle;
		echo "<br /><br /><br />";
		include ('header.php');
                        ...

 

I want to print out the page title on the page within the <?php and the ?> tags. how do i do that

 

I know print $pagetitle does not work. I thought I read online that, that works but I guess not.

 

 

Mbrown

 

 

Link to comment
https://forums.phpfreaks.com/topic/124950-solved-print-out-page-title/
Share on other sites

<?php
   echo "State Search";
?>

 

or

 

<?php
   echo "<title>State Search</title>";
?>

 

Though if you're making a hardcoded echo like that, no point in really putting it inside the tags.  Unless you were wanting that title to be dynamic, in which case you're going to have to come up with code to set $pagetitle to something.

<?php
   echo "State Search";
?>

 

or

 

<?php
   echo "<title>State Search</title>";
?>

 

Though if you're making a hardcoded echo like that, no point in really putting it inside the tags.  Unless you were wanting that title to be dynamic, in which case you're going to have to come up with code to set $pagetitle to something.

 

Isnt there a way i can set $PageTitle to what ever is in the <title></title>?

huh ???

 

you can do something like this

 

$title = "My first title";

it need to be above the echo part

 

<title><?php echo $title; ?></title>

 

but if you are having

<title>a title</title>

 

and want to get its content into a variable i dont know any way,or if its even possible.... :o

Perhaps you should explain what you're trying to accomplish because that doesn't really make sense.  Are you wanting to be able to have the title displayed, and then have a variable ($pagetitle) so you can somehow use it later on?  

 

<?php
 $pagetitle = "State Search";
 echo "<title>$pagetitle</title>";
?>

<!-- lots of stuff here -->

<?php 
 // do something with $pagetitle here
?>

 

I mean, I suppose you could like, use file_get_contents to have the file read itself and use some regex to grab what's between <title>..</title> or something but I mean, I hope you see how that sounds kind of ridiculous.  So uh...perhaps you should paint a picture of what you're overall goal here is...

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.