I have an generated output.js file from a specific device which contains Array in it:
var OUT=new Array (0x80,0x00,0x40,0x0026,0x0011,0x0014,0x0013,0x0018,0x0017,0x03FD,0x0116)
How can i get access to this array with PHP, so i can easily print specified Array[x] in any location:
print $OUT[4];
With simple JS i was able to do it like:
document.write(OUT[4]);
In case i can also handle that output.js with PHP like a txt file and then splitting and “doing like array thing” but i think there is away to use it right.. ^_^
Any tips or suggestions on that ? 🙂
Thnx!
If you want to fetch the file directly with PHP then you can either write a custom parser (using regular expressions if you can trust the file format to be consistant) or by interfacing with a JavaScript engine.
Otherwise, assuming the JavaScript is running in a web browser…
The simplest way to do this would be to make use of
createElementandappendChildwhile looping over an array to create aformelement containing ahiddeninput for each element of the array (with a name such asfoo[]to satisfy the algorithm PHP uses to populate$_POSTand friends) and thensubmit()the form.Alternatively, you could serialise the array to a string (e.g. a comma separated one if you know that there are no commas in the data) and create a query string with it (
var qs = "?foo=" + encodeURIComponent(serialised_array);) and then pass it using XMLHttpRequest.