1

Im working with data submitted from a jotform widget -when I run print_r($_POST) I get the following data

Array ( 
[formID] => 40923773875567 
[q1_clickTo] => Country: UNITED STATES
Province: Kentucky
Latitude: 37.568694
Longitude: -84.29632229999999
[website] => [simple_spc] => 40923773875567-40923773875567 
)

I need help in retrieving the country, province, latitude, longitude and website [simple_spc] data

please help - thank you

1
  • What is problem use indexed access like $a['website']['simple_spc'] ? Commented Apr 3, 2014 at 16:51

3 Answers 3

1

The problem you have is that your data in s1_clickTo is a string. I suggest getting your data in another format, because now you have to parse this yourself.

I would use explode() on new line \n (or \r\n depending on the actual format), and then for each key/value, explode on : or use RegEx to match.

Sign up to request clarification or add additional context in comments.

Comments

0

Access them in this way..

echo $_POST['q1_clickTo'];
echo $_POST['website']['simple_spc'];

Comments

0

May be its better to write some parser with closures like this?

$a = array(
   'formID' => '40923773875567',
   'q1_clickTo' => "Country: UNITED STATES
Province: Kentucky
Latitude: 37.568694
Longitude: -84.29632229999999",
   'website' => array(
      'simple_spc' => '40923773875567-40923773875567'
   )
);

$trim  = function($v) { return trim($v); };
$float = function($v) { return (float) $v; };

$mapping = array(
   'spc' => array('website', function($v) { return $v['simple_spc']; }),
   'data' => array('q1_clickTo', function($v) {
      $data   = explode("\n", $v);
      $result = [];
      foreach ($data as $line) {
          $parts = explode(':', $line);
          $result[$parts[0]] = $parts[1];
      }
      return $result;
   }),
   'country' => array('Country', $trim),
   'longitude' => array('Longitude', $float),
   'latitude' => array('Latitude', $float),
   'province' => array('Province', $trim)
);

$result = [];
foreach ($mapping as $key => $value) {
   $info = $a[$value[0]];
   $info = $value[1]($info);
   if (!is_array($info)) {
       $result[$key] = $info;
   } else {
      foreach ($info as $infoKey => $infoValue) {
          $a[$infoKey] = $infoValue;
      }
   }
}
var_export($result);

Working example here: http://sandbox.onlinephpfunctions.com/code/04f28278bb00b3ca0372d85a837537a2552bc248

Comments

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.