Last active
August 29, 2015 14:12
-
-
Save GiovanniGrieco/293530ad9aa7688877f2 to your computer and use it in GitHub Desktop.
Get terminal width - Cross-platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTerminalCols() | |
{ | |
$cols = 0; | |
if (defined('PHP_WINDOWS_VERSION_BUILD')) { | |
$cmdHandler = popen('more', 'r'); | |
$cmdInfo = fread($cmdHandler, 2096); | |
pclose($cmdHandler); | |
$cmdInfo = explode("\n", $cmdInfo); | |
$cols = trim(substr($cmdInfo[9], -4, 4)); | |
} else { | |
$cols = exec('tput cols'); | |
} | |
return $cols; | |
} | |
echo getTerminalCols(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment