Reputation: 374
In my php project I output several strings with long lengths. I want to cut these strings into pieces (All the same length) To format my output. In order to know how long these sections should be, I need to know the width of my ouput window. (CLI mode)
Is there any way I can detect the console width cross-platform?
Thanks
Upvotes: 1
Views: 2265
Reputation: 74018
Look at newt_get_screen_size. This gives you the rows and columns (window width) of your terminal.
If you're on Linux/Unix only, you can also use stty -a
and parse the output or use tput cols
.
See also How to get linux console $COLUMNS and $ROWS from PHP cli?.
Upvotes: 3