Page 1 of 1

Using php include for web page title tag

Posted: Wed Mar 03, 2010 8:49 pm
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
:)

Re: Using php include for web page title tag

Posted: Wed Mar 03, 2010 9:13 pm
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');

Re: Using php include for web page title tag

Posted: Wed Mar 03, 2010 9:37 pm
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