adamlacombe Posted July 23, 2009 Share Posted July 23, 2009 I can't seem to get this here to work: $r= array("forum", "tos"); $r2= array("Forum", "Terms Of Service"); $f = str_replace($r, $r2, $f); if($_GET['action'] == $r){ $title = $f; }else{ $title="Home"; } $title is in the title tags like this: <title>$sitename - $title</title> in another file but I want it so if, for example: ?action=tos it displays Terms of Service in the title tags instead of tos. Any idea why what I have might not be working? Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted July 23, 2009 Share Posted July 23, 2009 if($_GET['action'] == $r){ $r is an array, so $_GET['action'] would not equal that. Why not do this: <?php switch($_GET['action']){ case 'forum': $title = 'Forum'; break; case 'tos': $title = 'Terms of Service'; break; default: $title = 'Home' break; } ?> OR <?php $names = array( 'tos' => 'Terms of Service', 'forum' => 'Forum' ); if (in_array($_GET['action'],$names)){ $title = $names[$_GET['action']]; } else $title = 'Home'; ?> Quote Link to comment Share on other sites More sharing options...
Philip Posted July 23, 2009 Share Posted July 23, 2009 Why not just do like: // Setup an array with the pages and their names $titleArray = array('forum'=>'Forum', 'tos'=>'Terms of Service'); // if there is a page in the array with the one in the url if(isset($titleArray[$_GET['action']])) { // use the one in the array $title = $titleArray[$_GET['action']]; } else { // otherwise use a default $title = 'Home'; } Quote Link to comment Share on other sites More sharing options...
adamlacombe Posted July 23, 2009 Author Share Posted July 23, 2009 Thank you King Philip! ___________________ Wesf90, I cant do that bc $title has to be defined before the switch. Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted July 23, 2009 Share Posted July 23, 2009 Thank you King Philip! ___________________ Wesf90, I cant do that bc $title has to be defined before the switch. Of course it does, did you think I was going to write the entire script for you? Quote Link to comment Share on other sites More sharing options...
Philip Posted July 23, 2009 Share Posted July 23, 2009 <?php $names = array( 'tos' => 'Terms of Service', 'forum' => 'Forum' ); if (in_array($_GET['action'],$names)){ $title = $names[$_GET['action']]; } else $title = 'Home'; ?> in_array() looks for array values, not keys. Instead, you should use array_key_exists, or use isset like I did. Also, @OP: You probable want to do something like: $action = strtolower($_GET['action']); to make sure they match up since it is case sensitive. That way if a user puts script.php?action=TOS it still goes to the tos page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.