NYCPHP Meetup

NYPHP.org

[nycphp-talk] Passing JavaScript arrays

tedd tedd at sperling.com
Fri Jul 7 12:18:03 EDT 2006


At 11:44 AM -0400 7/7/06, Cliff Hirsch wrote:
>I need to pass data from PHP to JavaScript. Without resorting to any fancy Ajax's code, I currently build the JavaScript array variables using PHP echoes. Is this the best method? The arrays are visible in the HTML code. Any issues? For security, do I just escape the output like any other variable destined for the browser?
> 
>Regards,
>Cliff


Cliff:

To use a PHP variable in javascript, you create a javascript variable and then echo the value of the php variable. 

For example:

<?php
	$number = 100;
?>

<script language="javascript" type="text/javascript">
	var number = <?php echo $number; ?>;
</script>

hth's

tedd
-- 
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the talk mailing list