php call page title?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

php call page title?

Post by jayson.ph »

Hi all,

i have a 2 pages that using .php and the one page is for the content = home.php and the other 1 is for the title name page = title.php. and now i have no idea how to a call a title name into home.php

sample--> home.php

Code: Select all

<!DOCTYPE html>
<head>
<title><?php   ?></title>
</head>
<body>
</body>
</html>
-->title.php

Code: Select all

<?php echo "Philippines";?>
i want put Philippines name as a title and now how to call it into home.php

Please help..
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php call page title?

Post by social_experiment »

You can use 'include_once'; just make sure the path to the file is correct

Code: Select all

<title><?php include_once 'title.php';   ?></title>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: php call page title?

Post by pbs »

Use

<?php include("title.php");?>
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: php call page title?

Post by jayson.ph »

Thank you for the reply..

What if there are a lot of text content inside the title.php
sample:

Code: Select all

<?php echo "Philippines";?>
<?php echo "China";?>
<?php echo "Japan";?>
<?php echo "Autralia";?>
<?php echo "USA";?>
and i want only philippines should be an output into a title.. please help?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: php call page title?

Post by pbs »

Use "if" or "switch...case" for specific title
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php call page title?

Post by social_experiment »

If the title is dependant on certain conditions you will need a conditional statement to determine what is displayed; What will determine if you display 'philippines' ?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: php call page title?

Post by jayson.ph »

what phpscript should i use into home.php?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php call page title?

Post by social_experiment »

You can do the script on the title.php page and return the value
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: php call page title?

Post by jayson.ph »

ah okay but ah.. my main question here is ah a phpscript, like you answer earlier, that i use include but as i know include is to call a whole inside in the page.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php call page title?

Post by social_experiment »

jayson.ph wrote:my main question here is ah a phpscript, like you answer earlier, that i use include but as i know include is to call a whole inside in the page.
I don't understand the question completely so i've pasted an example to convey my reasoning; i hope this clears things up for you

Code: Select all

 // on inco_page.php
My name is <?php include_once 'page.php'; ?>
And inside page.php is this code

Code: Select all

<?php
	function total($var) {
		$name = $var;
		echo $name;
	}
	
	total('LavaBlob');
?>
Which will return "My name is LavaBlob " if you run inco_page.php
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php call page title?

Post by Celauran »

Well, what determines which title gets called? The title page you presented earlier with a bunch of echoes is never going to work.
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: php call page title?

Post by jayson.ph »

Thanks a lot guys for the cooperation and to you ==>social_experiment<== thank and now i have good idea because of you guys.. thanks
Post Reply