PhP,解析Json元素,不在数组中


PhP, Parse Json Element, Not in array

我有以下字符串。我只需要提取Model:或Orientation,或Software,并将其存储为变量。我遇到的问题是我不知道如何获得单个变量。有什么建议吗?

Model:  NIKON D200
Orientation:    0 
Resolution: 300.000 
ResolutionUnit: 2 
Software:   Nikon View 6.2.7 M
Date and Time:  2007:02:16 14:41:53
Exposure Time:  1/640 Sec
ISO Speed:  210
F Number:   8.0
Flash:  Yes, Strobe detected
Zoom Length:    32 mm
Exposure Program:   Manual
ISO Speed:  200 
Exposure Bias:  0.000 
Metering Mode:  Spot
Light Source:   Unknown
Zoom Length:    32 mm

这里有一个简单的函数来转换为关联数组。

// Convert a series of key:value lines to an associative array
function KeyValueLinesToAssocArray($lines) {
    $linesArray = explode("'n", $lines);
    print("Entries: " . count($linesArray) . "<br />");
    $assoc = array();
    foreach ($linesArray as $kv) {
        $kvs = explode(":", $kv, 2);
        if (2>count($kvs)) continue;
        $assoc[trim($kvs[0])] = trim($kvs[1]);
    }
    return $assoc;
}
$data = <<<DATA
Model:  NIKON D200
Orientation:    0 
Resolution: 300.000 
ResolutionUnit: 2 
Software:   Nikon View 6.2.7 M
Date and Time:  2007:02:16 14:41:53
Exposure Time:  1/640 Sec
ISO Speed:  210
F Number:   8.0
Flash:  Yes, Strobe detected
Zoom Length:    32 mm
Exposure Program:   Manual
ISO Speed:  200 
Exposure Bias:  0.000 
Metering Mode:  Spot
Light Source:   Unknown
Zoom Length:    32 mm
DATA;
// Now split the ExifCameraInfo string into an associative array
$exif = KeyValueLinesToAssocArray($data);
print $exif["Model"];