I have a JS variable:
var str = "hello world";
How could I pass this JS variable str
to a PHP variable like $str = this JS variable
?
echo $str; //output "hello world"
I have a JS variable:
var str = "hello world";
How could I pass this JS variable str
to a PHP variable like $str = this JS variable
?
echo $str; //output "hello world"
have you tried this?
<script type="text/javascript">
var str = 'hello world';
</script>
<?php
$roo = " <script type=\"text/javascript\">
document.write(str) ;
</script>";
echo $roo; // will print hello world
?>
EDit:
or use AJAX to get javascript variables .
You could add it to a postback event, and in your php read it from the posted data
using an xhr request you could then also print your output