Can javascript read a file to a string or array?

Status
Not open for further replies.

tscrap

New Member
Messages
14
Reaction score
0
Points
0
I am trying to find a javascript code which is similar to the PHP code file($file). (which reads the contents od the file $file to an array!) Is there anything available??
Thanks for spending time to read this!!
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Javascript can't read local files from the users computer unless you use a form with a file input and HTML5. Even then it is a bit hit and miss as some browser do not support the required functions.
If you want to load a file form the server you can use the XMLHttpRequest object and get the responseText or responseXML, depending on the format of the data.
Once you have the data loaded in either of these ways you can use arrays and string splitting just like you would in PHP, although Javascript is considerably less reliable and fast as PHP.
 

tscrap

New Member
Messages
14
Reaction score
0
Points
0
I dont want to open files in the users computer! I want to open a URL with JS!!
Is it possible???
 

vishal

-::-X10 Guru-::-
Community Support
Messages
5,255
Reaction score
192
Points
63
**Duplicate Thread**
closed
 
Last edited:
Status
Not open for further replies.
Top