Possible Duplicate:
Inserting PHP array into Javascript array
I'm reading a file in server with php and storing the file content in a variable. now i want to access the variable with javascript, Since I need to split the contents with tab delimited and add the content as options to a Select tag.
<?php
//read the 'file' content to lines variable
$lines = file('file');
?>
Javascript to access the PHP variable($lines):
<script type="text/javascript" >
function readData(){
var s = '<? echo $lines ?>';
alert(s);
}
</script>
Where alert pops up only with Array text
What Should I do so that the data stored in $lines array will be accessed in javascript array variable
file_get_contents('file')
instead of file('file')
is your best bet.