-2
<html>
<head>
<body>
 <script>
    mynumber=19;
    <?php
        /*****PHP Script****/
    ?>
 </script>
</body>
</html>

can you guys help me write PHP script in that position that can display value of variable javascript mynumber that is 19, and displaying it with PHP variable.

i was confuse to convert it from javascript variable to PHP variable...

Thanks for the help.

mlms133
  • 53
  • 6
  • 1
    http://stackoverflow.com/questions/2338942/access-a-javascript-variable-from-php – trainoasis Jan 18 '15 at 18:38
  • 1
    Short answer is you can't, and you probably don't need to. What are you trying to achieve here? If you want to parameterize a PHP script, use the query parameter, for example: myscript.php?mynumber=12. Then PHP can access it via $_GET['mynumber']. If you want to communicate with the server during run-time, send an AJAX call in the same fashion. If the value is persisted on the client-side, use a cookie; if persisted on the server, use either a database or a persistent memory storage. – Schien Jan 18 '15 at 18:43
  • Javascript variables don't exist at the time or in the environment PHP is executed. – JAL Jan 18 '15 at 18:43
  • see my comment here http://stackoverflow.com/questions/27851653/how-to-post-text-to-html-with-php – Axel Amthor Jan 18 '15 at 18:43

2 Answers2

0

You can't do like this. Please understand javascript is client side scripting langauge and php is server side langauge.

When you execute the code or load page, first server side code executed afterwards client side.

For Ex:-

<html>
<head>
<body>
 <script>
    mynumber=19;
    <?php
        /*****PHP Script****/
      echo $mynumber;
    ?>
 </script>
</body>
</html>

It will throw an error undefine variable $mynymber;

But if you want to pass javascript variable to php server side you can do that using Ajax. php-Ajax

Saurabh
  • 101
  • 1
  • 8
0

Use AJAX, but it is possible to read the .php or .html file with the same php script and parse the lines containing "var something = 1337, weirdthing = -1337.1337"

1000Gbps
  • 1,455
  • 1
  • 29
  • 34