curl does not give output as string instead of array curl does not give output as string instead of array curl curl

curl does not give output as string instead of array


Make serverA print your data in JSON format using json_encode() instead of print_r():

echo json_encode(listFolders($dir));

Then the output of cURL (which will be a JSON array STRING) can be converted to array using json_decode():

$dir_array = json_decode($stringReturnedByCURL);

cURL is an HTTP client. The only thing it does is returning the string containing the HTML web page. In this web page you can put that JSON array.

This way you're using HTTP to transport your data encoded in JSON from serverA to serverB.The output of the page in your question just prints the array in print_r format, which does not have a function to decode that format.

WARNING: you need to print the JSON only, remove that echo "<pre>"; of the json_decode() in serverB will find an unexpected <pre> in the code he has to decode.


Try to return the array in JSON format.

eg. return json_encode($return)

edit 1

if you want to transfer some these kind of data then you have to do it in JSON format or the xml