Small HTML Question

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
BigAbe
Forum Commoner
Posts: 66
Joined: Fri Mar 31, 2006 7:41 pm

Small HTML Question

Post 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 --
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post 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.
Post Reply