将JSON数据中的数字修剪为PHP

I'm trying to store the numbers from the strings on: http://driftsdata.statnett.no//snpsrestapi/PowerData/PowerOverview/se?callback=Production.UpdateData

To my database, as these varies every hour.

However, preg_replace and str_replace doesnt work for me, as it only prints out "22" instead of "22 340" as it sais on the website.

here is my code:

for($i=0; $i<6; $i++) {
    $info = get_data($countries[$i], $text);
    for($j=0; $j<8; $j++) {
        $info[$j] = preg_replace('/\s+/', '', $info[$j]);
$info[$j] = (int)$info[$j];

any help?

Since you are dealing with json format, the cleanest and safest way is to use json_decode():

<pre>
<?php
$jsontext = preg_replace('~^[^(]*+\(|\)$~', '', $text);

$json = json_decode($jsontext);

foreach($json->production as $prod) {
    printf("<br/><strong>%s</strong><br/>%s\t%s\t%s\t%s\t%s",
        $prod->type, $prod->se, $prod->dk, $prod->no, $prod->fi, $prod->ee);
    $result[$prod->type] = preg_replace('~[ -]~', '',
        array($prod->se, $prod->dk, $prod->no, $prod->fi, $prod->ee));
}
echo '<br/>' . print_r($result, true);
?>
</pre>