I'm working on a new Symfony 2 project which will be a panel management for Docker containers.
In this project, I'm executing some commands with the exec()
PHP function.
I'm trying to parse the output of the following command :
docker create tutum/lamp:latest --name test 2>&1
When the command is a success I'm getting the container ID in a string which is good and easy to use but when a problem occured it's not the same. The result is a string with a var="data" syntax which I want to parse in order to get an array.
The command output :
time="2015-06-21T11:33:26+02:00" level="fatal" msg="Error response from daemon: Conflict. The name \"test\" is already in use by container XXXXXXXX. You have to delete (or rename) that container to be able to reuse that name."
I wish to have something like that :
Array( time => "2015-06-21T11:33:26+02:00", level => "fatal" ...);
I know that I have to do a regex parsing. After a while (regex and me are not realy best friends) I get this regex (tested on https://regex101.com/) :
/([a-zA-Z]+)="((.*)*)"/
I used preg_split function i'm not sure that it's the good one.
preg_split('/([a-zA-Z]+)="((.*)*)"/', $output)
Result is :
array(2) { [0]=> string(0) "" [1]=> string(0) "" }
Have you any suggestions to help me ? Many thanks for your help.