Hi, how much I look for; I can't find the answer to the solution of the question There is a bash script that is run using php (binds to the CMS), when launched, it (the bash script) returns the result as

------------------------------------------------------------------ IMPORTANT ------------------------------------------------------------------ Account created loginname= "login", password= "password" ------------------------------------------------------------------ 

How can I parse the loginname and password values ​​using the same PCP?

    1 answer 1

    I did not check the code, but it should work:

     function getCredentials($input, $output) { preg_match('/'.$input.'=\s"(.*?)"/', $output, $matches); if(empty($matches[1])) { return null; } return $matches[1]; } $output = shell_exec('command'); $login = getCredentials('loginname', $output); $passsword = getCredentials('passsword', $output); 

    The function accepts the attribute and output of the console and finds the value.

    Or you can do it a little differently:

     function getCredentials($output) { preg_match_all('/=\s"(.*?)"/', $output, $matches); var_dump($matches); if(empty($matches[1])) { return null; } return $matches[1]; } 

    But in this case, it is not clear what could eventually come to the answer, ideally, the answer should be:

     array(2) { [0]=> string(5) "login" [1]=> string(8) "password" } 
    • one
      I apologize for the long response. The solution helped, thanks! - Andrey Voronov