Strange, This PHP seems to be correct, but it cannot get the correct result.
$ Screen_w = "script document. write (screen. width); script "; if ($ screen_w <500) {echo 'width less than 500 ';} else {echo' greater than or equal to 500 ';}
Directly echo $ screen_w; the correct result is 1366.
If the result is 1366 or less than 500.
If (int) $ screen_w or intval ($ screen_w)
It is displayed as 0.
Why?
Reply to discussion (solution)
Is it true if there is no syntax error?
1. php is executed before js! Even if $ screen_w = "script" document. write (screen. width); script "; can get data, it is after the php code is executed.
2. $ screen_w = "script document. write (screen. width); script";
What is it? It is only a string value assignment.
Even with echo $ screen_w;
It is only displayed in the browser.
Var_dump is a 46-bit string, and the JS code is included. match the number with the regular expression and then compare it.
I don't know how to get the numbers.
I used to have this problem, but the foundation is not strong.
Js and php should be separated,
First, you must understand what is the client code and what is the server code. Second, the server code is executed first, and the client code is executed later.
However, php cannot get the screen width. I want to write a sentence to judge that when the screen width is smaller than the width of the main content, no floating bar will be output that will block the content.
These questions are almost the only way for new users. for more than a decade (even in the past, haha), why don't I write this in all kinds of teaching materials?