Jump to content

[SOLVED] using strings and variables


Lamez

Recommended Posts

alright, cuz I am lazy, and if one day I decided to change the title, I do not want to change tons of pages so I wanted started while I was ahead.

 

I have a file, like most webmasters, called head.php

 

in head it contains, well my header, and a little php snippet that says:

 

<title><?php include ("style/include/cons/title.php"); ?></title>

and in title.php:

Lamez's Corner - <?php
if $title = home{
echo "Home";
}
elseif $title = login{
echo "Login";
}
elseif $title = register{
echo "Register";
}
elseif $title = member{
echo "Member's Area";
}
elseif $title = admin{
echo "Admin's Center";
}
?>

 

the reason why I am tell you this is because I want to type a variable in my HTML coding that will give the page a title for example:

 

<?php 
$title == home;
include "style/include/cons/head.php"; 
?>

 

well it did not work out, that is why I am posting here, I get this error:

Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /mounted-storage/home48c/sub007/sc33591-LWQU/www/style/include/cons/title.php on line 3

 

line three in title.php is:

if $title = home{

 

I am guessing the main problem is I am not setting the variables right, or not calling the variable right.

 

Any Help?

 

 

Link to comment
Share on other sites

Setting the variable should be

 

$title = "home";

 

and calling it in the if statement should be

 

if ($title == "home") {

 

Also, your include statement is wrong - the filename should be contained in brackets

 

include "style/include/cons/head.php";

should be

include("style/include/cons/head.php");

Link to comment
Share on other sites

you need to do it like this:

 

Lamez's Corner - <?php
if ($title == "home") {
echo "Home";
}
else if ($title == "login") {
echo "Login";
}
else if ($title == "register"){
echo "Register";
}
else if ($title == "member") {
echo "Member's Area";
}
else if ($title == "admin") {
echo "Admin's Center";
}
?>

 

and then you will have to query your "title" variable in your urls:

 

like this:

 

http://www.domain.com/page1.php?title=home

Link to comment
Share on other sites

no that is not what I am trying to do :(

 

in the title bar I want it to call the variable.

 

up on the title bar (if title equals to home)

 

"Lamez's Corner - Home : Mozilla Firefox"

 

I am not too sure if i was clear enough on my first post.

Link to comment
Share on other sites

just declare the variable before the include.

 

<title><?php
$title="home";
include ("style/include/cons/title.php"); 
?></title>

 

and use this for your include:

 

Lamez's Corner - <?php
if ($title == "home") {
echo "Home";
}
else if ($title == "login") {
echo "Login";
}
else if ($title == "register"){
echo "Register";
}
else if ($title == "member") {
echo "Member's Area";
}
else if ($title == "admin") {
echo "Admin's Center";
}
?>

Link to comment
Share on other sites

I would use a switch statement instead of the if-elseif:

Lamez's Corner - 
<?php
    switch ($title) {
       case 'home':
       case 'login':
       case 'register':
            echo ucwords($title);
            break;
       case 'member':
            echo "Member's Area";
            break;
       case 'admin':
           echo "Admin's Center";
           break;
       default:
           echo "No Title";
    }
?>

 

Ken

Link to comment
Share on other sites

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.