Home  >  Article  >  Backend Development  >  How to get js variables in php

How to get js variables in php

angryTom
angryTomOriginal
2019-10-19 18:00:024864browse

How to get js variables in php

How to get js variables in php

When using php to build a website, we often need to interact with the front-end page Interaction, sometimes we also need to get the value in the js variable through php. In this case, we can get the variable by embedding the js code in it.

1. First, we create a test php file.

How to get js variables in php

2. Add the code required for html inside.

How to get js variables in php

3. We add a js script inside and define a variable 100.

How to get js variables in php

4. Now we add the php code at the bottom, in which we define a b variable with a default value of 0, ready to use it To receive the value of a in js.

How to get js variables in php

5. Then we use writeln in the script to output a and assign it to the variable b in php. At the end The echo output checks the value in b.

How to get js variables in php

6. Opening this php file in the browser will directly echo the value of variable a in js as 100. At this point, php has completed obtaining the variables in js.

How to get js variables in php

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to get js variables in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn