Using php include for web page title tag

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
aussiewebgirl
Forum Newbie
Posts: 6
Joined: Wed Mar 03, 2010 8:38 pm

Using php include for web page title tag

Post by aussiewebgirl »

Hi,

I am an absolute beginner to php but have over 10 years experience in html and web design. I have worked with many sites using php but cannot actually write any myself.

My question is - and I have scoured google and forums and tutorials but cannot find an answer or how to do this -

I have the following code in the title tags of my web pages:

Code: Select all

<title><?php include('includes/lang.php'); echo "$title_mainpage"; ?></title>
&

Code: Select all

<title><?php include('includes/lang.php'); echo "$title_anotherpage"; ?></title>

and the following code in a lang.php file

Code: Select all

$title_mainpage = "My great web page";

Code: Select all

$title_anotherpage = "My other great web page";
This is my first basic (okay - stop laughing - at least it works :oops: ) php scripting and I would like to know how to do this properly without having to have the

Code: Select all

php include('includes/lang.php');
before every echo statement.

Thanks,

aussiewebgirl
:)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Using php include for web page title tag

Post by AbraCadaver »

There are a lot of possibilities, but here is a simple example that you may adjust for your needs or may spark some other ideas:

file 'header.php'

Code: Select all

<?php include('includes/lang.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-us">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title><?php echo $title_mainpage; ?></title>
</head>
yourpage.php

Code: Select all

include('includes/header.php');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
aussiewebgirl
Forum Newbie
Posts: 6
Joined: Wed Mar 03, 2010 8:38 pm

Re: Using php include for web page title tag

Post by aussiewebgirl »

Thank you so much AbraCadaver - you are wicked for such a quick reply! I've been working on this all day and knew it was a fairly painless process but just couldn't get it right.

I had tried putting the line

Code: Select all

<?php include('includes/lang.php'); ?>
at the top of my page but it kept showing up at the top of the browser. I must have had the syntax incorrect.

I will forge on and expand my php skills.

Thanks again,

aussiewebgirl :P
Post Reply