- preg_match_all: documentation ( source)
- implode: documentation ( source)
<?php
$response = '{"data":[{"access_token":"EAAby7f21xKABALPCThZC63i4LZAHZC7MaYbQ0E5gN","id":"515968102105625"},{"access_token":"EAAby7f21xKABAK0zyfHCVNBE0Nn3g1XZCWuXzZA4T","id":"1338263602879836"}],"paging":{"cursors":{"before":"NTE1OTY4MTAyMTA1NjI1","after":"MTMzODI2MzYwMjg3OTgzNgZDZD"}}}';
if (preg_match_all('#"access_token":[^"]*"([^"]*)"#', $response, $datos)) {
$mp = $datos[1];
} else {
// Tipo array con clave error.
$mp = array('error' => 'No existen Access Tokens');
}
$cast = implode(',',$mp);
foreach($mp as $P){
$page = $P[0];
$token2 = $P[1];
}
echo $token2."<br/>";
echo $page;
?>