Skip to content

Instantly share code, notes, and snippets.

@GiovanniGrieco
Last active August 29, 2015 14:12
Show Gist options
  • Save GiovanniGrieco/293530ad9aa7688877f2 to your computer and use it in GitHub Desktop.
Save GiovanniGrieco/293530ad9aa7688877f2 to your computer and use it in GitHub Desktop.
Get terminal width - Cross-platform
<?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