0 votes
in SoSci Survey (English) by s057462 (330 points)
edited by SoSci Survey

Hi Dominik
we are back at this question (sorry I cannot find the original question on this any more).

We want to send responses (data) from a RT task to a server which computes sth and we wan to use the output in the very survey on the next page.

We compile the responses from the assignment questions S101 and S102 :

$xml = '<?xml version="1.0" encoding="UTF-8"?'.'>';
$xml.= '<myData attr="ID">'.htmlspecialchars(caseNumber()).'<saveEnv save="false"/>';

for ($n = 0; $n < 80; $n++) {
    $xml.= '<data attr="'.id('S101', $n+1).'">'.htmlspecialchars(value(id('S101', $n+1))).'</data>\n'; 
}; 

for ($n = 0; $n < 80; $n++) {
    $xml.= '<data attr="'.id('S102', $n+1).'">'.htmlspecialchars(value(id('S102', $n+1))).'</data>\n';  
};
$xml.= '</myData>';
 

We send the responses from the assignment question S101 :

$answer = sendXML('http://dd.virtualpsyclab.net/ddgem/ddgem', $xml);
debug($answer);

and we receive the attached debug response:
Debug Information for $answer:
name html, attr[Array], value , children [Array]

We then use

list($yes) = explode('\t', $answer);

and get the error:

explode() expects parameter 2 to be string, array given

The other server send back in mine type text/plain the following content (presumably that's what $answer contains):

Content-type:text/plain\r\n\r\n <html>\n<head>\n<title>Hello</title>\n</head>\n<body>\nOK    77.4805609906267    79.1893024286756    1.7087414380489    87.3463465801849    9.86578558955824    120.361186224957    42.8806252343308    43.6180475963458</body>\n</html>\n

How can we access that answer in soscisurvey?
And do you have any tips to be able to debug as we cannot see the contents of $answer?

Thank you for your help.

by SoSci Survey (330k points)
Please make use of the {} button, when you include code in your questions. I have edited that above.

1 Answer

0 votes
by SoSci Survey (330k points)
list($yes) = explode('\t', $answer);

The explode function will only work on a string, so if you put "a,b,c" in that, you will get back an array with ['a', 'b', 'c']. What you have in $answer is already an array. This is why PHP says:

explode() expects parameter 2 to be string, array given

Actually, you seem to get some XML back starting with , so you receive an HTML page back. And if you try a debug($answer['children']) then you will probably see that it contains a <head> and a <body> element. Within the <body> there may be your data or an error message.

To debug that I recommend using the developer tools of the browser. You can create requests to the external server there, including your request XML.

In the second answer, you see the same. That's also the HTML code of a page. If the content is the same like above, the you see that the content of the <body> text is actually the content that you're looking for:

OK    77.4805609906267    79.1893024286756    1.7087414380489    87.3463465801849    9.86578558955824    120.361186224957    42.8806252343308    43.6180475963458

This is something that you could prepare and decode. How to get that from the XML in the first example? Please post what this tells you:

debug($answer['children']);

If you would like to process the second answer, you would use the preg_match() function to extract the part between <body> and </body>.

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...