2017-02-13 26 views
0

这里是我的API格式:无法获得所需的文本响应

http://api.example.com/balance.php?format=#format&token=#token 

//Output text 

#username|#balance|#error_code|#resText 

这里是我的PHP代码:

<?php 

$url="http://api.example.com/balance.php?format=text&token=ExAmPlEToKeN"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($ch, CURLOPT_HTTPGET, true); 


$output = curl_exec($ch); 

$balance = $output; /* Help me here to get the balance from the response */ 

curl_close($ch);  

echo "Balance is:".$balance; 

?> 

这说明:

平衡是:my_username | 500.00 | 0 |成功

但我只需要表现出这样的平衡:

余额为:500.00

请帮帮我!

+0

用'|'分解并得到你需要的东西。 –

+0

我该怎么做?我对这些并不熟悉。@u_mulder –

+1

努力并运用你的优秀解决技巧。 –

回答

0

像u_mulder说使用爆炸()函数

$balance="my_username|500.00|0|Success" ; 
$ar =explode ('|', $balance); 
$amount =$ar [1]; 
echo "Balance is:".$amount; 

我分裂了清晰的代码,但你可以,如果你想将它压缩为一条直线。

+0

它的工作!谢谢! –