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 ....
-
can you describe in details??? – Kishan Gajjar Apr 13 '11 at 12:12
-
you want to split data using javascript? – Love Sharma Apr 13 '11 at 12:12
6 Answers
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>

- 49,507
- 13
- 108
- 140
Create whole javascript using PHP just like you're doing it with HTML

- 156,878
- 40
- 214
- 345
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>

- 7,588
- 12
- 53
- 62
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/

- 2,614
- 3
- 18
- 16
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.

- 1,843
- 17
- 30
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.

- 13,803
- 5
- 45
- 72