Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

2 of 3
insert duplicate link

Accessing data stored in Php array in javascript

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

Emmi
  • 223
  • 1
  • 2
  • 8
default

AltStyle によって変換されたページ (->オリジナル) /