1

how to pass the data which is stored in a variable from php to javascript and by using split function we are spliting the data and display it on the web age ....

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133

6 Answers6

3

At the risk of being shouted at for answering without context, I'm in a generous mood today :)

<?php 
   //do lots of stuff in my PHP page
   $var = 'somevalue';
?>
<html> 
  <head>
    <title>My page title</title>
    <script type='text/javascript'>
        var myJsVar = '<?php echo $var;?>'
    </script>
  </head>
  <body>
  </body>
</html>
JohnP
  • 49,507
  • 13
  • 108
  • 140
0

Create whole javascript using PHP just like you're doing it with HTML

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

Assuming that you are writing the javascript in the .php file, you can write something like this

<script type="text/javascript">

var name = '<?php echo $name ; ?>';

</script>
naiquevin
  • 7,588
  • 12
  • 53
  • 62
0

The best way to do it, is by using JSON (a format for communication between server-side and client-side) http://www.javascriptkata.com/2007/05/08/how-to-use-json/

Dnns
  • 2,614
  • 3
  • 18
  • 16
0

If you're not constructing the JavaScript in the php, and if it's only a small amount of data, you could also put it on the page in a hidden variable, and use JavaScript to access it that way.

Amy Anuszewski
  • 1,843
  • 17
  • 30
0

As mentioned several times before you can just echo the content of the var within the javascript part of the webpage. But if you want to split the information to show in the webpage, you could this with PHP aswell.

Explode is the equivalent of Split in PHP. Perhaps you can explode it in PHP and show the values directly in the correct place.

Hugo Delsing
  • 13,803
  • 5
  • 45
  • 72