Max Snijders
Max Snijders

Reputation: 374

PHP Command Line Window Width

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

Answers (2)

Sam Dark
Sam Dark

Reputation: 5291

exec('mode con', $output);

Then parse what's returned.

Upvotes: 3

Olaf Dietsche
Olaf Dietsche

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

Related Questions