如何在不包含额外内容的情况下获取返回数据的值

An api is sending back data in this format x[[seconds:cost[[x i'm using php and javascript, how do I retrieve the seconds only, than retrieve the cost only

so for example they would send back something like this

x[[16413:2.60[[x

how can i get the values of seconds/cost without all that extra x[[ stuff included?

i want just the seconds

than i want just the cost

Use regular expression to parse the string.

In JavaScript:

var s = 'x[[16413:2.60[[x';

var parts = s.match(/([.0-9]+):([.0-9]+)/);
var seconds = parts[1];
var cost = parts[2];
alert(seconds);
alert(cost);

In PHP:

$s = 'x[[16413:2.60[[x';

preg_match('/([.0-9]+):([.0-9]+)/', $s, $parts);
$seconds = $parts[1];
$cost = $parts[2];
echo $seconds . "; " . $cost;