NYCPHP Meetup

NYPHP.org

[nycphp-talk] Passing JavaScript arrays

Cliff Hirsch cliff at pinestream.com
Fri Jul 7 12:37:42 EDT 2006


And still use htmlentities if I am passing a string?

-----Original Message-----
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




More information about the talk mailing list