Page 1 of 1

Small HTML Question

Posted: Mon Jun 05, 2006 2:33 pm
by BigAbe
I've been coding html and such for quite some time now, but I was just curious if there way (outside of using variables) to specify a page as a 'this' entity.

Here's what I mean.

Let's say I have an index.php page with tons of various includes. Inside these includes are links referring to index.php (plus a few variables being passed here and there).

I want to change up some stuff in my index.php page and switch to say index2.php and run the same includes.

Is there a way to have my links say something like "this.php" to where I can just change the main index file name without having to go inside each include and manually change each and every link?

Just wondering what fellow site admins do when outside the presence of a CMS.

Any thoughts would be appreciated!

-- Abe --

Posted: Mon Jun 05, 2006 3:35 pm
by RobertGonzalez
Anytime information (even static information) is going to be referenced more than once I tend to use language/text arrays...

<?php

Code: Select all

$sitetext = array();
$sitetext['file_suffix'] = '.php';
$sitetext['index_page'] = 'index';
$sitetext['welcome'] = 'Welcome to ';
$sitetext['text_link'] = '<a href="%s">%s</a>';
$sitetext['return_home'] = 'Return to our home page';
?>
Then I call them throughout the script as needed...

Code: Select all

<?php
echo sprintf($sitetext['text_link'], $sitetext['index_page'].$sitetext['file_suffix'], $sitetext['return_home']);
?>
There's a lot more you can do with a setup like this. This is just a small example.

Posted: Mon Jun 05, 2006 3:35 pm
by TheMoose
Depending on your php config, you can do either $_SERVER['PHP_SELF'], or $PHP_SELF. It will reference the current file you are in.