Catch the data inside a result json_decode

1

How would I get the value of the login string and password inside a json_decode? What happens is that when I bring the result of a curl:

$obj = json_decode($output);

The following message appears:

  

Your access data is: login: xxxxx and password: YYYY

I tried to log in as follows:

list($mensagem,$login) = explode("login:",$obj->info->cidade[0]->dados[0]->mensagem);

But it returns:

  

xxxxx and password: YYYY

You should only get the XXXXX for the login and YYYY for the password.

    
asked by anonymous 12.05.2016 / 20:40

1 answer

4

It is possible to resolve this problem with a% regex of% that captures : \w+ followed by a space and one or more characters ( : ).

To access the login and password use: a-z0-9_ and $m[0][1] , $m[0][2] can be discarded because it is the string $m[0][0] .

$str = 'Seus dados de acesso é: login: xxxxx e senha: YYYY';

preg_match_all('/: \w+/i', $str, $m);
echo "<pre>";
print_r($m);

Output:

Array
(
    [0] => Array
        (
            [0] => : login
            [1] => : xxxxx
            [2] => : YYYY
        )

)
    
12.05.2016 / 21:00