Home > Article > Backend Development > How to get the variable value of js in php
When using php to build a website, we often need to interact with the front-end page. Sometimes we also need to use php to obtain the value in the js variable. In this case We can obtain this variable by embedding js code in it.
First we create a test php file. (Recommended learning: PHP programming from entry to proficiency)
Add the code required for html.
We add a js script inside and define a variable 100.
Now we add the php code at the bottom, which defines a b variable that defaults to 0, and is ready to use it to receive the value of a in js.
Then we use writeln in the script to output a, and assign it to the variable b in php, and finally echo output to view the value in b.
Opening this php file in the browser will directly echo that the value of variable a in js is 100. At this point, php has completed obtaining the variable in js.
The above is the detailed content of How to get the variable value of js in php. For more information, please follow other related articles on the PHP Chinese website!