I just want a string as string. When I try to get a the string via $auth["token"] it keeps showing me the string type and I cannot get the string alone
`
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.nowpayments.io/v1/auth',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"email": "email",
"password": "pass"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
var_dump($response);
$auth =json_decode($response,true);
var_dump($auth);
curl_close($curl);
$authtoken=$auth["token"];
echo $authtoken;
`
the page shows this 'error'
string(164) "{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzODUzMj3MzkiLCJpYXiOjE2NjgzMTAwNTQsImV4cCI6MTY2DMxMDM1NH0.mSgMgaixpBG4pkWalx7oJSPx5DRRAOzUWRTk"}" array(1) { ["token"]=> string(152) "eyJhbGciOiJIUzI1NiIsInR5I6IkpXVCJ9.eyJpZCI6IjYzODUzMjU3MzkiLCJpYXQiOjE2NjgzTAwNTQsImV4cCI6MTY2ODMxMDM1NH0.mSgMCz5jcXkgaixpBG4pkWalx7oJSPx5DRAOzUWRTk" } eyJhGciOiJIUzI1NiIsInR5cCI6J9.eyJpZCI6IjYzODUzMjU3MzkiLCJpYXQiOjE2NjgzMTAwNTsImV4cCI6MTY2ODMxMDM1NH0.mSgMCz5jcXkgaixppkWalx7oJSPx5DRRAOzUWRTkstring(128) "
as you can see i just want $authtoken without the 'string(128)' string info everytime
and here is with var_export($auth);
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzODUzMjU3MzkiLCJpYXQiOjE2NjgzMTE5ODYsImV4cCI6MTY2ODMxMjI4Nn0.nK0WDgA9fwhVT6EqNimQm32NlRh5UL4kv6x3AAP_yi8',
and here is with var_export($reponse);
'{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzODUzMjU3MzkiLCJpYXQiOjE2NjgzMTM2ODMsImV4cCI6MTY2ODMxMzk4M30.rU0It2195Kg5I9aaZXpvnEBMshjzTowyl0RbpQbnHew"}'string(128) "
CodePudding user response:
Try this:
$token = var_export($auth['token'],1);
echo $token;