Well, I have a function that draws links that act like tabs on a web page. Basically, I have an array of links to use as tabs, all of this nature:
$aTabs[] = array("Mode" => "something", "Title" => "Something Else");
Once I have added all the tabs, I would like to use this function to print them:
function drawTabs($aTabs, $sFilename) {
global $iMode;
foreach ($aTabs as $aTab) {
$sClass = "Tab";
if ($iMode == $aTab["Mode"]) {
$sClass .= " CurTab";
}
echo "<a class=\"{$sClass}\" href=\"{$sFilename}?Mode={$aTab["Mode"]}\">{$aTab["Title"]}</a>\n";
}
}
So that seems all fine and dandy as it is. It works just fine.
I would also like to use it in another part of the site, which is using URL rewriting to make things look a little neater. In that part of the site, the output needs to be
echo "<a class=\"{$sClass}\" href=\"{$sFilename}/{$aTab["Mode"]}/\">{$aTab["Title"]}</a>\n";
I was thinking of adding in a string replace that would do something like this:
str_replace("[mode]", $aTab["Mode"], $sFilename);
so that I could call
drawTabs($aTabs, "/some/place/on/my/site/[mode]/");
and most likely adding in a conditional so that if there is no ‘[mode]’ in $sFilename, it would just add it to the end using ‘?Mode=$aTab[“Mode”]’.
My question is, does my logic seem correct, or is there some more simple way of doing this?
A solution could be something like this
Then to use it