As a simple example, I want to write a CLI script which can print = across the entire width of the terminal window.
#!/usr/bin/env php
And there's stty, from coreutils
$ stty size
60 120 # <= sample output
It will print the number of rows and columns, or height and width, respectively.
Then you can use either cut or awk to extract the part you want.
That's stty size | cut -d" " -f1 for the height/lines and stty size | cut -d" " -f2 for the width/columns