Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:15:37+00:00 2026-06-10T23:15:37+00:00

Well, I have a function that draws links that act like tabs on a

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:15:38+00:00Added an answer on June 10, 2026 at 11:15 pm

    A solution could be something like this

    function drawTabs($aTabs, $sFilename, $sFormat = null) {
        global $iMode;
    
        $sFormat = $sFormat ?: "<a class=\"[class]\" href=\"[fileName]?Mode=[mode]\">[title]</a>\n";
    
        foreach ($aTabs as $aTab) {
            $sClass = "Tab";
            if ($iMode == $aTab["Mode"]) {
                $sClass .= " CurTab";
            }
    
            $replacements = array(
                '[class]' => $sClass,
                '[fileName]' => $sFilename,
                '[mode]' => $aTab["Mode"],
                '[title]' => $aTab['Title'],
                );
                echo strtr($sFormat, $replacements);
    
        }
    }
    

    Then to use it

    $sFormat = "<a class=\"[class]\" href=\"[fileName]/[mode]/\">[title]</a>\n";
    
    drawTabs($aTabs, $sFilename, $sFormat);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a popup function in a program that works well, be re-loads the
Well i have a web page hosted in a IIS 7.0 now the problem
I have an Nx4 array of vertices that I'd like to plot using glVertexArray
I have a page with an input box, and a function that processes the
I have the following function which works very well within a $(document).ready(function(){ $('.threadWrapper >
I understand the JS .sort() function well enough, and I have a loose grasp
well i have a configuration like this in the components part of my config
Well i have a div tag that i show as a modal dialog this
well I have that problem, im using a lightbox srcipt and im opening an
Well I have been writing in the same style for awhile now and all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.