The14thGOD Posted March 2, 2007 Share Posted March 2, 2007 I was wondering, I have a navigation on my site, that is pretty long, and it would probably change over time, so I wanted to make it an include. The problem is however, I need to detect on certain pages variables that I send to the URL. I need to do this in order to give a certain part of the navigation a new class so that it is highlighted. So basically, is there a way for PHP to detect which page is loaded (ie. index.php, about.php, gallery.php)? Could someone perhaps point me in the right direction? Thanks, The14thGOD Quote Link to comment Share on other sites More sharing options...
chronister Posted March 2, 2007 Share Posted March 2, 2007 http://us3.php.net/reserved.variables Take note of $_SERVER['PHP_SELF'] Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted March 2, 2007 Author Share Posted March 2, 2007 Thank you, I will take a look at this. Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted March 2, 2007 Author Share Posted March 2, 2007 Hey, another question kind of relating to this same one. Is there a way to "echo" a large amount of html w/o using echo on each line of html? Thanks Quote Link to comment Share on other sites More sharing options...
Orio Posted March 2, 2007 Share Posted March 2, 2007 You could either close and open php, or use heredoc. Example for the "open & close": <?php //Some regular php... $a = 1; $b = $a + 1; //Let's stop to print some html! ?> <tag> </tag> <?php //We can continue with our php echo $a; ?> Heredoc Heredoc is a way to output, just like you can use double quotes or single quotes. More info here. Example: <?php //We want to echo some html! echo <<<HEREDOC <html> <head> <title>Hi!</title> </head> <body> </body> </html> HEREDOC; ?> Hope it helps, Orio Quote Link to comment Share on other sites More sharing options...
fekaduw Posted March 2, 2007 Share Posted March 2, 2007 i faced similar problem some time before and i solved it using the following code. to access which page is being displayed use $url=getenv("SCRIPT_NAME"); //this will simply assign the whole path of the page to URL variable and to check the exact page i just used: if(strcmp(substr($url,-9,9),"index.php")==0) { //code goes here.... } but the 9 and -9 depends on the length of the url it may help Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted March 2, 2007 Author Share Posted March 2, 2007 Thanks for the quick replies, I think I'll look into the here doc as that looks to be pretty simple =D. The14thGOD Quote Link to comment Share on other sites More sharing options...
chronister Posted March 3, 2007 Share Posted March 3, 2007 Or you can simply do <?php echo '<table > <tr><td>Some Text</td></tr> <tr><td>Some Text</td></tr> <tr><td>Some Text</td></tr> <tr><td>Some Text</td></tr> <tr><td>Some Text</td></tr> <tr><td>Some Text</td></tr> <tr><td>Some Text</td></tr> <tr><td>'.$some_variable.'</td></tr> </table>' ?> But I prefer to open and close php as in the first example. 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.