0

today I'm trying to pass an array from PHP to Python. I've looked around all the examples of passing soething from PHP to Python have all be all passing strings. When trying to 'recreate' what was done I get Notice: Array to string conversion in C:\xampp\htdocs\wrapper.php on line 7, and then no output. My PHP code is:

//$info is an array of values
exec("C:\Users\MrPete\AppData\Local\Programs\Python\Python38-32\python.exe C:\xampp\htdocs\test.py $info", $output, $return);
print_r($output);
echo '<br>';

and my python code is:

import sys



info = sys.argv[1]

for i in info:
    print (i)

I was wondering if someone could tell me what I'm doing wrong--and how to fix it.

5
  • Which one of the 4 lines you show us is line 7? Commented Apr 2, 2020 at 20:44
  • What is $info? Commented Apr 2, 2020 at 20:44
  • 1
    I doubt that PHP arrays and Python arrays are compatable. Have you considered using JSON as the format for moving data from one thing to another, its easier than XML and what it was designed for Commented Apr 2, 2020 at 20:46
  • @RiggsFolly $info is an array, as stated in the comments. Line 7 is the exec in the PHP, and I thought about if using json would be the answer--I'll go and give that a shot. Commented Apr 2, 2020 at 20:50
  • 1
    If python easily supports JSON then go with @RiggsFolly suggestion. Commented Apr 2, 2020 at 20:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.