下面的文件可以使用 PhotoShop 中具有 XMP 数据的任何 JPG 文件进行设置。在 'pattern' 中,将 'eat:' 替换为 'dc:' 或从 '$string' 返回的任何命名空间。
使用以下数组设置调用 $string (1) 它会生成一个 print_r 数组,如下所示: (2)
如果取消注释上面的行 (1a),它将打印到浏览器,复制并粘贴到下面的行 (1a)。这应该产生一个看起来像这样的数组:(3)
为什么 print_r 读数不同,当它是相同的字符串时?
我如何让它表现得像(3);...更好的是我如何让它像(4)一样结束?
<?php
header("Content-Type: text/html; charset=utf-8");
$filename = "2012-04-24_WestCoast_2.jpg";
echo '<img src="'. $filename . '" alt="'. $filename . '" title="' . $filename . '" width="350" /><p />';
$source = file_get_contents($filename);
$xmpdata_start = strpos($source,'<x:xmpmeta');
$xmpdata_end = strpos($source,"</rdf:Description>");
$xmplenght = $xmpdata_end-$xmpdata_start;
$xmpdata = substr($source,$xmpdata_start,$xmplenght+18);
$string = htmlentities($xmpdata); //(1)
//if (is_string($string)) {
// echo "is a string\n"; //TRUE
//} else {
// echo "is not a string\n";
//}
//$string = print_r("'".$string."';");
// (1a)=====================================
//$string = '<x:xmpmeta xmlns: === Truncated for simplicity ===x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:Description>';
$pattern = '/eat:(.*?)="(.*?)"/is';
preg_match_all($pattern, $string, $matches);
$group = array($matches[1], $matches[2]);
// foreach($group as &$match);
echo '<pre>';
// print_r ($match);
print_r ($group);
echo '</pre>';
?>
(2)======================================
//如果我只是调用'$string ',这就是我得到的:
Array
(
[0] => Array
(
)
[1] => Array
(
)
)
(3)=======================================
// 如果我取消注释 (1),则我粘贴在文件中的'$string',我得到了这个:
Array
(
[0] => Array
(
[0] => Biography
[1] => Title
[2] => object_description
[3] => Medium
[4] => in_height
[5] => in_width
[6] => in_depth
[7] => Dated
[8] => Photograph
)
[1] => Array
(
[0] => American B1942 Castine, Maine
[1] => Reunion Dinner Party at the Slanted Door
[2] => Nancy Freeman, Tim Patterson The Slanted Door San Francisco Calf.
[3] => photography
[4] => 2736
[5] => 3648
[6] => @ 240 dpi
[7] => April 24, 2012
[8] => PrimaryImage
)
)
(4)======================================
//这就是我想要的得到太:
Biography: American B1942 Castine, Maine
Title: Reunion Dinner Party at the Slanted Door
object_description: Reunion Dinner Party at the Slanted Door
Nancy Freeman, Tim Patterson The Slanted Door San Francisco Calf.
Medium: photography
in_height: 2736
in_width: 3648
in_depth: @ 240 dpi
Dated: April 24, 2012
Photograph: PrimaryImage