Lamez Posted December 15, 2007 Share Posted December 15, 2007 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 https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/ Share on other sites More sharing options...
themistral Posted December 15, 2007 Share Posted December 15, 2007 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 https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415423 Share on other sites More sharing options...
phpQuestioner Posted December 15, 2007 Share Posted December 15, 2007 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 https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415431 Share on other sites More sharing options...
Lamez Posted December 15, 2007 Author Share Posted December 15, 2007 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 https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415436 Share on other sites More sharing options...
phpQuestioner Posted December 15, 2007 Share Posted December 15, 2007 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 https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415445 Share on other sites More sharing options...
kenrbnsn Posted December 15, 2007 Share Posted December 15, 2007 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 https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415454 Share on other sites More sharing options...
phpQuestioner Posted December 15, 2007 Share Posted December 15, 2007 either one would work: if/else or switch Link to comment https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415457 Share on other sites More sharing options...
Lamez Posted December 15, 2007 Author Share Posted December 15, 2007 thanks guys! thank you very much! for a noob, this was probably my most dynamic PHP script on my own, and I was almost right! Thanks Again! Link to comment https://forums.phpfreaks.com/topic/81774-solved-using-strings-and-variables/#findComment-415474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.