PHP FUNCTION ee_extract_exif_from_pscs_xmp

Because latest Adobe Photoshop (CS) does not embed EXIF data to images any more, but embeds EXIF into XMP instead, I wrote this function to read those SMP tags back to EXIF for further use.
I specifically intented to write this without using PHP's XML parser functions.
Feel free to improve this, post new versions for all to see. My mail is pekka A T photography-on-the.net

<?php

$xmp_parsed 
ee_extract_exif_from_pscs_xmp ("CRW_0016b_preview.jpg",1);

function 
ee_extract_exif_from_pscs_xmp ($filename,$printout=0) {
    
    
// very straightforward one-purpose utility function which
    // reads image data and gets some EXIF data (what I needed) out from its XMP tags (by Adobe Photoshop CS)
    // returns an array with values
    // code by Pekka Saarinen http://photography-on-the.net
    
    
ob_start();
    
readfile($filename);
    
$source ob_get_contents();
    
ob_end_clean();
    
    
$xmpdata_start strpos($source,"<x:xmpmeta");
    
$xmpdata_end strpos($source,"</x:xmpmeta>");
    
$xmplenght $xmpdata_end-$xmpdata_start;
    
$xmpdata substr($source,$xmpdata_start,$xmplenght+12);
    
    
$xmp_parsed = array();
    
    
$regexps = array(
    array(
"name" => "DC creator""regexp" => "/<dc:creator>\s*<rdf:Seq>\s*<rdf:li>.+<\/rdf:li>\s*<\/rdf:Seq>\s*<\/dc:creator>/"),
    array(
"name" => "TIFF camera model""regexp" => "/<tiff:Model>.+<\/tiff:Model>/"),
    array(
"name" => "TIFF maker""regexp" => "/<tiff:Make>.+<\/tiff:Make>/"),
    array(
"name" => "EXIF exposure time""regexp" => "/<exif:ExposureTime>.+<\/exif:ExposureTime>/"),
    array(
"name" => "EXIF f number""regexp" => "/<exif:FNumber>.+<\/exif:FNumber>/"),
    array(
"name" => "EXIF aperture value""regexp" => "/<exif:ApertureValue>.+<\/exif:ApertureValue>/"),
    array(
"name" => "EXIF exposure program""regexp" => "/<exif:ExposureProgram>.+<\/exif:ExposureProgram>/"),
    array(
"name" => "EXIF iso speed ratings""regexp" => "/<exif:ISOSpeedRatings>\s*<rdf:Seq>\s*<rdf:li>.+<\/rdf:li>\s*<\/rdf:Seq>\s*<\/exif:ISOSpeedRatings>/"),
    array(
"name" => "EXIF datetime original""regexp" => "/<exif:DateTimeOriginal>.+<\/exif:DateTimeOriginal>/"),
    array(
"name" => "EXIF exposure bias value""regexp" => "/<exif:ExposureBiasValue>.+<\/exif:ExposureBiasValue>/"),
    array(
"name" => "EXIF metering mode""regexp" => "/<exif:MeteringMode>.+<\/exif:MeteringMode>/"),
    array(
"name" => "EXIF focal lenght""regexp" => "/<exif:FocalLength>.+<\/exif:FocalLength>/"),
    array(
"name" => "AUX lens""regexp" => "/<aux:Lens>.+<\/aux:Lens>/")
    );
    
    foreach (
$regexps as $key => $k) {
            
$name         $k["name"];
            
$regexp     $k["regexp"];
            unset(
$r);
            
preg_match ($regexp$xmpdata$r);
            
$xmp_item "";
            
$xmp_item = @$r[0];
            
array_push($xmp_parsed,array("item" => $name"value" => $xmp_item));
    }
    
    if (
$printout == 1) {
        foreach (
$xmp_parsed as $key => $k) {
                
$item         $k["item"];
                
$value         $k["value"];
                print 
"<br><b>" $item ":</b> " $value;
        }
    }

return (
$xmp_parsed);

}

?>

USAGE EXAMPLE:

$myarray = ee_extract_exif_from_pscs_xmp ("UPLOAD/myimage.jpg",0);

OUPUT EXAMPLE (when second parameter == 1):

DC creator: Joe D'Aperture
TIFF camera model: Canon EOS 10D
TIFF maker: Canon
EXIF exposure time: 1/25
EXIF f number: 35/10
EXIF aperture value: 361471/100000
EXIF exposure program: 4
EXIF iso speed ratings: 400
EXIF datetime original: 2003-11-13T19:05:06Z
EXIF exposure bias value: 0/1
EXIF metering mode: 5
EXIF focal lenght: 28/1
AUX lens: 28.0-135.0 mm