How to make things line up in command line with tabs?
up vote
-1
down vote
favorite
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
|
show 3 more comments
up vote
-1
down vote
favorite
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
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
|
show 3 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
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
php windows command-line-interface
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
|
show 3 more comments
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
|
show 3 more comments
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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