Inport an external js array into php?

Discussion in 'PHP' started by blahmartinblah, Mar 2, 2008.

  1. #1
    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.
     
    blahmartinblah, Mar 2, 2008 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    matthewrobertbell, Mar 2, 2008 IP
  3. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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, Mar 2, 2008 IP
  4. blahmartinblah

    blahmartinblah Active Member

    Messages:
    431
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    93
    #4
    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?
     
    blahmartinblah, Mar 2, 2008 IP
  5. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    Cybernaut, Mar 2, 2008 IP
  6. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I assumed the javascript array was runtime,
    not hardcoded
    I am still stuck in desktop-mode :eek:

    off topic:
    i read this one last week
    http://www.nicklewis.org/node/962#comment-50681
    seems interesting as alternative to fetching
     
    juust, Mar 2, 2008 IP
  7. blahmartinblah

    blahmartinblah Active Member

    Messages:
    431
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    93
    #7
    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.
     
    blahmartinblah, Mar 4, 2008 IP