How to make things line up in command line with tabs?











up vote
-1
down vote

favorite
1












I often do things like this on the command line:



<?php

echo 'Short description:' . "tttttt" . '123' . "n";
echo 'A slightly longer description:' . "tttttt" . '321' . "n";

?>


These will no longer "match up"; "123" and "321" will not be on the same "column":



This is what I want



This is what I don't want



Is there any sane way to get around this problem? I always used to think that the whole point of the "tabulator" was to achieve this effect, but clearly it's not? Or have I misunderstood it somehow?










share|improve this question






















  • I believe you want a table. Google html table, it will do magic for you
    – Andreas
    Nov 11 at 7:25






  • 1




    @Andreas I think he wants to use php on the command line
    – Andreas
    Nov 11 at 7:26












  • If you are using PHP, will this be used on many terminals? You should consider using space delimited output (The post office did...). Write a "tab" subroutine in PHP if you are concerned about bloat.
    – benc
    Nov 11 at 7:31










  • Space delimited output? Same problem exists for that...
    – Old StackDonald
    Nov 11 at 7:33






  • 1




    Well, you could have at look at climate (climate.thephpleague.com) if you are creating a cli app with php.
    – Andreas
    Nov 11 at 7:40















up vote
-1
down vote

favorite
1












I often do things like this on the command line:



<?php

echo 'Short description:' . "tttttt" . '123' . "n";
echo 'A slightly longer description:' . "tttttt" . '321' . "n";

?>


These will no longer "match up"; "123" and "321" will not be on the same "column":



This is what I want



This is what I don't want



Is there any sane way to get around this problem? I always used to think that the whole point of the "tabulator" was to achieve this effect, but clearly it's not? Or have I misunderstood it somehow?










share|improve this question






















  • I believe you want a table. Google html table, it will do magic for you
    – Andreas
    Nov 11 at 7:25






  • 1




    @Andreas I think he wants to use php on the command line
    – Andreas
    Nov 11 at 7:26












  • If you are using PHP, will this be used on many terminals? You should consider using space delimited output (The post office did...). Write a "tab" subroutine in PHP if you are concerned about bloat.
    – benc
    Nov 11 at 7:31










  • Space delimited output? Same problem exists for that...
    – Old StackDonald
    Nov 11 at 7:33






  • 1




    Well, you could have at look at climate (climate.thephpleague.com) if you are creating a cli app with php.
    – Andreas
    Nov 11 at 7:40













up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1





I often do things like this on the command line:



<?php

echo 'Short description:' . "tttttt" . '123' . "n";
echo 'A slightly longer description:' . "tttttt" . '321' . "n";

?>


These will no longer "match up"; "123" and "321" will not be on the same "column":



This is what I want



This is what I don't want



Is there any sane way to get around this problem? I always used to think that the whole point of the "tabulator" was to achieve this effect, but clearly it's not? Or have I misunderstood it somehow?










share|improve this question













I often do things like this on the command line:



<?php

echo 'Short description:' . "tttttt" . '123' . "n";
echo 'A slightly longer description:' . "tttttt" . '321' . "n";

?>


These will no longer "match up"; "123" and "321" will not be on the same "column":



This is what I want



This is what I don't want



Is there any sane way to get around this problem? I always used to think that the whole point of the "tabulator" was to achieve this effect, but clearly it's not? Or have I misunderstood it somehow?







php windows command-line-interface






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 7:20









Old StackDonald

1




1












  • I believe you want a table. Google html table, it will do magic for you
    – Andreas
    Nov 11 at 7:25






  • 1




    @Andreas I think he wants to use php on the command line
    – Andreas
    Nov 11 at 7:26












  • If you are using PHP, will this be used on many terminals? You should consider using space delimited output (The post office did...). Write a "tab" subroutine in PHP if you are concerned about bloat.
    – benc
    Nov 11 at 7:31










  • Space delimited output? Same problem exists for that...
    – Old StackDonald
    Nov 11 at 7:33






  • 1




    Well, you could have at look at climate (climate.thephpleague.com) if you are creating a cli app with php.
    – Andreas
    Nov 11 at 7:40


















  • I believe you want a table. Google html table, it will do magic for you
    – Andreas
    Nov 11 at 7:25






  • 1




    @Andreas I think he wants to use php on the command line
    – Andreas
    Nov 11 at 7:26












  • If you are using PHP, will this be used on many terminals? You should consider using space delimited output (The post office did...). Write a "tab" subroutine in PHP if you are concerned about bloat.
    – benc
    Nov 11 at 7:31










  • Space delimited output? Same problem exists for that...
    – Old StackDonald
    Nov 11 at 7:33






  • 1




    Well, you could have at look at climate (climate.thephpleague.com) if you are creating a cli app with php.
    – Andreas
    Nov 11 at 7:40
















I believe you want a table. Google html table, it will do magic for you
– Andreas
Nov 11 at 7:25




I believe you want a table. Google html table, it will do magic for you
– Andreas
Nov 11 at 7:25




1




1




@Andreas I think he wants to use php on the command line
– Andreas
Nov 11 at 7:26






@Andreas I think he wants to use php on the command line
– Andreas
Nov 11 at 7:26














If you are using PHP, will this be used on many terminals? You should consider using space delimited output (The post office did...). Write a "tab" subroutine in PHP if you are concerned about bloat.
– benc
Nov 11 at 7:31




If you are using PHP, will this be used on many terminals? You should consider using space delimited output (The post office did...). Write a "tab" subroutine in PHP if you are concerned about bloat.
– benc
Nov 11 at 7:31












Space delimited output? Same problem exists for that...
– Old StackDonald
Nov 11 at 7:33




Space delimited output? Same problem exists for that...
– Old StackDonald
Nov 11 at 7:33




1




1




Well, you could have at look at climate (climate.thephpleague.com) if you are creating a cli app with php.
– Andreas
Nov 11 at 7:40




Well, you could have at look at climate (climate.thephpleague.com) if you are creating a cli app with php.
– Andreas
Nov 11 at 7:40












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Here is one method.

Maybe not as simple as you expected but it works.

I use the full string and find the longest description and use that as the base.



$str = "Short description: t 123
A slightly longer description: t 321";

$arr = explode ("n", $str);
foreach($arr as $line){
// Create new array with str_len as one item
$parts = explode("t", $line);
$new = ['desc' => $parts[0], 'num' => $parts[1], 'len' => strlen($parts[0])];
}
// Find max length in array
$pad = max(array_column($new, 'len'))+1;

// Output it
foreach($new as $sub){
echo str_pad($sub['desc'], $pad, " ") . "t" . $sub['num'] . "n";
}


Output:



Short description:                   123
A slightly longer description: 321


https://3v4l.org/s1DAD






share|improve this answer





















  • Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
    – Old StackDonald
    Nov 11 at 20:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246656%2fhow-to-make-things-line-up-in-command-line-with-tabs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Here is one method.

Maybe not as simple as you expected but it works.

I use the full string and find the longest description and use that as the base.



$str = "Short description: t 123
A slightly longer description: t 321";

$arr = explode ("n", $str);
foreach($arr as $line){
// Create new array with str_len as one item
$parts = explode("t", $line);
$new = ['desc' => $parts[0], 'num' => $parts[1], 'len' => strlen($parts[0])];
}
// Find max length in array
$pad = max(array_column($new, 'len'))+1;

// Output it
foreach($new as $sub){
echo str_pad($sub['desc'], $pad, " ") . "t" . $sub['num'] . "n";
}


Output:



Short description:                   123
A slightly longer description: 321


https://3v4l.org/s1DAD






share|improve this answer





















  • Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
    – Old StackDonald
    Nov 11 at 20:31















up vote
0
down vote













Here is one method.

Maybe not as simple as you expected but it works.

I use the full string and find the longest description and use that as the base.



$str = "Short description: t 123
A slightly longer description: t 321";

$arr = explode ("n", $str);
foreach($arr as $line){
// Create new array with str_len as one item
$parts = explode("t", $line);
$new = ['desc' => $parts[0], 'num' => $parts[1], 'len' => strlen($parts[0])];
}
// Find max length in array
$pad = max(array_column($new, 'len'))+1;

// Output it
foreach($new as $sub){
echo str_pad($sub['desc'], $pad, " ") . "t" . $sub['num'] . "n";
}


Output:



Short description:                   123
A slightly longer description: 321


https://3v4l.org/s1DAD






share|improve this answer





















  • Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
    – Old StackDonald
    Nov 11 at 20:31













up vote
0
down vote










up vote
0
down vote









Here is one method.

Maybe not as simple as you expected but it works.

I use the full string and find the longest description and use that as the base.



$str = "Short description: t 123
A slightly longer description: t 321";

$arr = explode ("n", $str);
foreach($arr as $line){
// Create new array with str_len as one item
$parts = explode("t", $line);
$new = ['desc' => $parts[0], 'num' => $parts[1], 'len' => strlen($parts[0])];
}
// Find max length in array
$pad = max(array_column($new, 'len'))+1;

// Output it
foreach($new as $sub){
echo str_pad($sub['desc'], $pad, " ") . "t" . $sub['num'] . "n";
}


Output:



Short description:                   123
A slightly longer description: 321


https://3v4l.org/s1DAD






share|improve this answer












Here is one method.

Maybe not as simple as you expected but it works.

I use the full string and find the longest description and use that as the base.



$str = "Short description: t 123
A slightly longer description: t 321";

$arr = explode ("n", $str);
foreach($arr as $line){
// Create new array with str_len as one item
$parts = explode("t", $line);
$new = ['desc' => $parts[0], 'num' => $parts[1], 'len' => strlen($parts[0])];
}
// Find max length in array
$pad = max(array_column($new, 'len'))+1;

// Output it
foreach($new as $sub){
echo str_pad($sub['desc'], $pad, " ") . "t" . $sub['num'] . "n";
}


Output:



Short description:                   123
A slightly longer description: 321


https://3v4l.org/s1DAD







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 7:44









Andreas

14.6k31441




14.6k31441












  • Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
    – Old StackDonald
    Nov 11 at 20:31


















  • Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
    – Old StackDonald
    Nov 11 at 20:31
















Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
– Old StackDonald
Nov 11 at 20:31




Well, it's interesting if nothing else. My own cobbled-together hack used a fixed "horizontal position", but this appears to figure that out on its own... Worth studying.
– Old StackDonald
Nov 11 at 20:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246656%2fhow-to-make-things-line-up-in-command-line-with-tabs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues