Test Mtruk response parse - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Your result can be seen below.

Result of php executing

Full code of Test Mtruk response parse.php

  1. <?php
  3. $answer = '<?xml version="1.0" encoding="ASCII"?><QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd"><Answer><QuestionIdentifier>taskAnswers</QuestionIdentifier><FreeText>[{"explanation":"Very interesting image, depicting return from the Mars.","option1":{"imageB":false},"option2":{"imageA":true}}]</FreeText></Answer></QuestionFormAnswers>';
  4. $xml = simplexml_load_string($answer);
  5. $json = json_encode($xml);
  6. $array = json_decode($json, TRUE);
  7. // print_r($array);
  9. print_r($array['Answer'][1]['FreeText']);
  11. ?>
File Description
  • Test Mtruk response parse
  • PHP Code
  • 21 Sep-2021
  • 595 Bytes
You can Share it: