Is it possible to pass an array as a command line argument to a PHP script?

前端 未结 9 882
忘掉有多难
忘掉有多难 2020-12-09 16:37

I\'m maintaining a PHP library that is responsible for fetching and storing incoming data (POST, GET, command line arguments, etc). I\'ve just fixed a bug that would not all

9条回答
  •  臣服心动
    2020-12-09 16:43

    In case, if you are executing command line script with arguments through code then the best thing is to base encode it -

    base64_encode(json_encode($arr));
    

    while sending and decode it while receiving in other script.

    json_decode(base64_decode($argv[1]));
    

    That will also solve the issue of json receiving without quotes around the keys and values. Because without quotes, it is considered to be as bad json and you will not be able to decode that.

提交回复
热议问题