I want to import the contents of a javascript array that is served as part of a page on a remote server, and use the data it in php code on my local server. I don't have access to modify or add any code on the remote server, think of this as 'scraping' a javascript array. I've spent an hour searching and can't come up with any ideas for a way to do this elegantly. Can anyone help? Martin.
It seems to me that you'll need to preg_match the page source then do another preg match on the js array to get the array keys and data, good luck
if it is a once off 'spy', you might try something like firebug https://addons.mozilla.org/en-US/firefox/addon/1843?id=1843&application=firefox javascript has an imposed cross-domain scripting block, so you cannot access any other script from a page that is not on the same domain, but the browser itself doesnt have that restriction, so you can use bookmarklets or browser integrated code, add-ons
juust: Thanks, this isn't once off, it must run daily to update a database on the local machines server. It must be done from php. I haven't heard of the "cross-domain scripting block" before, but it seems pretty easy to just copy the remote file to the local server to circumvent that? Supposing it could be worked around, do you have a further suggestion?
Fetch that page from remote server, extract that piece of code of javascript array using regex and use json extension of php 5 load js array into a php array. json will let you save php array as js array too.
I assumed the javascript array was runtime, not hardcoded I am still stuck in desktop-mode off topic: i read this one last week http://www.nicklewis.org/node/962#comment-50681 seems interesting as alternative to fetching
Hi Cybernaut, can you give me a little bit more detail, an example, or some related web links? I searched a bit and can't really find much. Hope you can help! Martin.