I've been able to mix PHP and JS, but only in ONE direction. That is, passing PHP vars to JS functions, e.g., using an "onClick" event. You pass the PHP $var_name to the JS function, and everything works fine.
But going the other way is damned near impossible, since PHP runs server side and JS only runs client side (well, almost).
You will probably end up solving your screen resolution size using JS alone -- sorry. PHP just can't handle that. But you could move into Java proper, with it's big, bloated, baggage package, and tedious development path to accomplish this.
But before I'd tackle all that "C++ like" Java crapolla, I'd try anything I could find in JS to get this to work.
HTH