0

I'm trying to get data from import io in php format, however that doesn't work with pagination, so have had to do it in javascript (code below) however i need to put it into a database so I guess php would be the best (or at least easiest for me). My question is how can i convert a javascript array into a php array.

thanks,

MsKazza

<!DOCTYPE html>
<html>
<head>
  <title>Import&bull;io Example</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- 1. Include the client library -->
  <script src="https://cdn.import.io/js/2.0.0/importio.js"></script>

<!-- 2. Configure the library -->
  <script type="text/javascript">
    importio.init({
      "auth": {
        "userGuid": "4e3524b0-5ff7-4102-9710-f96246a8303c",
        "apiKey": "oX9ksC/OQXxeO6dXYlNTgl8Juuh2SkCpdih2f0xH9d+3tzoBT0CsFuLr+ZlWPxVLbylL9XHQ8dLxNJvrKc2AUg=="
      },
      "host": "import.io"
    });

    // Data and done callbacks
    var dataCallback = function(data) {
      console.log("Data received", data);
      for (var i = 0; i < data.length; i++) {
        var d = data[i];
        for (var k in d.data) {
          document.write("<i>" + k + "</i>: " + d.data[k] + "<br />");
        }
        document.write("<hr>");
      }
    }
    var doneCallback = function(data) {
      console.log("Done, all data:", data);
      document.write("<b>Done</b><hr>");
    }

// 3. Do the query (when the function is called)
    var doQuery = function() {
      // Query for tile goldenwherewhen
      importio.query({
        "connectorGuids": [
          "83c211ab-91a1-4e54-9838-dc086bc1b527"
        ],
        "input": {
          "what": "hotels",
          "where": "ireland"
        }
      }, { "data": dataCallback, "done": doneCallback });

    }
  </script>
  <style>body { text-align: center; } button { line-height: 20px; color: #333; text-align: center; text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75); vertical-align: middle; cursor: pointer; border: 1px solid #CCC; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffe6e6e6',GradientType=0); filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),0 1px 2px rgba(0, 0, 0, 0.05); -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),0 1px 2px rgba(0, 0, 0, 0.05); outline: 0; padding: 11px 19px; font-size: 17.5px; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; color: #FFF; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); background-color: #EC3C87; background-image: -moz-linear-gradient(top,#EE4E93,#E92076); background-image: -webkit-gradient(linear,0 0,0 100%,from(#EE4E93),to(#E92076)); background-image: -webkit-linear-gradient(top,#EE4E93,#E92076); background-image: -o-linear-gradient(top,#EE4E93,#E92076); background-image: linear-gradient(to bottom,#EE4E93,#E92076); background-repeat: repeat-x; border-color: #E92076 #E92076 #AC1153; border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee4e93',endColorstr='#ffe92076',GradientType=0); filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); }</style>
  <body>
    <button onClick="doQuery()">Query</button>
    <p style="margin-top: 0"><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAABaCAMAAADtqqpJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAvFQTFRFUVJST1BQUFFR/////f39TE1N/v7+TU5OUlNTTk9PSElJSUpK/Pz8WltbU1RU+Pj4SktLRkdHS0xM+/v7R0hI9/f3YmNjV1hYiouL5ubm7e3tVVZW9PT0VFVVXF1dQUJCRUZGWFlZ3t7e39/f9vb22dnZ8/PzzMzM0NDQ5OTk8fHx6urqyMjI+vr6X2Bg+fn5YGFhYWJif4CA8PDwjY6O6enp7Ozsc3R0cXJyi4uL7u7uZ2hoz8/PhoeHtre3kJGRmJmZQEFBqqqq2tvbkpOTnJ2d7+/vg4ODeXp6o6Oj9/j4goOD6+vrr7Cw1dXV1NTUbG1tysrKwcHB1dbWh4iIlJSUxMTEi4yMZmdnxsfHcnJyVldXd3h4vr6+TE5Orq+vZGVlY2RkQ0RE4eHhuLi44uLi3d3dzs/P09PT5+jofn9/x8fH29zcl5mZl5eXlpeXRkhIamtrra2tp6ioWVpabW5uXV5ePT4+cHFxw8PDQUNDx8jI19fX6OjobG5uPD09yMnJpqampaWlampqpqiok5WVvb29REZGnZ6era6u/v//1tfXvr+/kJCQdnd3gICA9PX1g4SE4ODgrK2tS01Nk5SUdHV1wMDAv8DAwMHBaWpq6unpREVFhIWFt7e38vLyv7+/fX19fX9/W1xccXFxioqKpqenaGhoTU1NXmBg4+Tke3x8QkNDZGRk0dHRWVtbZmVlh4eHf39/z9DQj4+Ps7Ozb3Bwc3Nz5eXljo+PSkxMUFBQ8vPz3Nzc9fX13NvbVVVVVFRU3t3deHl5oKCgU1NTdXZ25+fnuLm5ubm5a2xspKWlenp6wcLC9vf38fLyuru71NXVqKiow8TEm5ycsbKysbGx7e7uaGpqhoaGUlJSfn5+zc7O1tbWvLy8zc3N0tLS6uvrysvLoaKinp6edXV1/f7+zM3NiImJaGlp2tra8/T0TU9P29vb/Pv7bm9veHp69fb2XF5emZmZ6+rq+vv7s7S0u7y8lJWVZWZm////lMTowQAAAPt0Uk5T/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wDjnwPIAAAD80lEQVR42uzYU9AmRxQG4NMYf7bx27bXtm1nrZgbZze2bdu2bdtWX2X+3eAitZsvmz4Xqdq5mpqaear7nHd6ahqEnEPNE/zvV0GKzU49/9W9vsXS/RFrv6U/R5H00gsogPP0ShzdnTKAeK8r5ih6STsBMOC0WziGvsgLADpNN1QUydcd81123Slo2X2jfum6+wPTHnuc6iQdebtctp4YZJedVk1vPoMkV5dzyfrLTlsnzp79Q0SzBh/CperqGz67MGD1sJ92X6WcMPW9ei5R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AAAAElFTkSuQmCC" /></p>
  </body>
</html>
4
  • 1
    I don't see an array. I only see a chunk of code. Are we supposed to execute it to see what the array looks like? Commented Nov 24, 2014 at 11:16
  • I won't waste too much time looking at your code but I suggest you use JSON. Convert your array into JSON string and then send it to PHP, where it can be converted to array using json_decode(). See : php.net/manual/en/function.json-decode.php Commented Nov 24, 2014 at 11:20
  • this question is answered here. stackoverflow.com/questions/9880904/… Commented Nov 24, 2014 at 11:21
  • i'm sorry i don't usually work with javascript i assumed it was as the output looks like an array. Please see : adlantic.ie/importio/goldenwherewhen.html for output. If its not then how can i convert this to php to extract info. thanks :) Commented Nov 24, 2014 at 11:25

1 Answer 1

1

You can do this in many ways, two of the "best" would be

1, sending variables in the format variable[key] = value php will reconise this and do the the conversion so $_GET['variable']['key'] would contain value. http://php.net/manual/en/language.variables.external.php

2, send it as a JSON string use JSON.stringify(yourArray); (NOTE: IE8 and above support this, older versions need a libary like json2), then in php call json_decode() on the variable. http://php.net/manual/en/function.json-decode.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.