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 6201533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:34:20+00:00 2026-05-24T04:34:20+00:00

I have this in my code echo $result[‘arr’][‘sub’].\t\t\t\t.$result[‘arr2’][‘sub2’]; I am sending it through headers

  • 0

I have this in my code

echo $result['arr']['sub']."\t\t\t\t".$result['arr2']['sub2'];

I am sending it through headers to a text file, but it shows up like this:

Subject              Description
Test                 Checking to see it it works
A long string             pushes my description to the side

How can I “fix” the formatting, so that the second column always lines up vertically, regardless of the length of text in the first column?

  • 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-05-24T04:34:20+00:00Added an answer on May 24, 2026 at 4:34 am

    I think that you have misunderstood what tab spaces do. They don’t magically consider text in the following lines; they just jump to the next free tab stop as configured by the display medium.

    If the preceding text already went past a tab stop then, yes, it’ll be skipped.

    Perhaps you want a fixed-width margin after the first column.

    Determine the number of spaces that you want to use (perhaps by taking the length of the longest item in the first column, and adding some padding width), then append that to each value in the first column with str_repeat, remembering to subtract the number of characters actually present in that field.


    Perhaps like this, with a fixed first-column width of 20:

    <?php
    $column_width = 20;
    foreach ($data as $result) {
       echo $result['arr']['sub'];
       echo str_repeat(' ', $column_width - strlen($result['arr']['sub']));
       echo $result['arr2']['sub2'];
       echo "\n";
    }
    ?>
    

    (I haven’t accounted for the case where text in the first column exceeds a length of 20 characters.)


    Or perhaps like this, with the clever expanding that I described up above:

    <?php
    $margin = 5;
    $column_width = 0;
    foreach ($data as $result) {
       $column_width = max($column_width, strlen($result['arr']['sub']));
    }
    $column_width += $margin;
    foreach ($data as $result) {
       echo $result['arr']['sub'];
       echo str_repeat(' ', $column_width - strlen($result['arr']['sub']));
       echo $result['arr2']['sub2'];
       echo "\n";
    }
    ?>
    

    (Here the first column automatically expands, so it doesn’t really matter how long it is.)


    Live demo of both approaches.


    Further work may include programtically limiting the length of text in the first column to something sensible for your output context, but I’ll leave that up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
I have this code: $summize = new summize; $search = $summize->search('#test'); $text = $search->results[0]->text;
I have this code: btn_jouer.onRelease = function () { verif = txt_email_user.text; if (txt_email_user.text
I have this code here which gives me the result I'm looking for, a
I have a result set that is being returned using this code: while ($row
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {

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.