function write_XMP_array_to_text($xmparray) { // Add the XMP packet header // The sequence 0xEFBBBF is the UTF-8 encoded version of the Unicode �zero // width non-breaking space character� (U+FEFF), which is used for detecting // whether UTF-16 or UTF-8 is being used. $output_XMP_text = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n"; // Photoshop Seems to add this, but there doesn't appear to be // any information on what it means // TODO : XMP, Find out what the adobe-xap-filters tag means $output_XMP_text .= "<?adobe-xap-filters esc=\"CR\"?>\n"; // Add the XML text $output_XMP_text .= write_xml_array_to_text($xmparray, 0); // The XMP standard recommends adding 2-4k of white space at the // end for in place editing, so we will add it to the XML now $output_XMP_text .= str_repeat(" \n", 30); // Add the XMP packet trailer $output_XMP_text .= "<?xpacket end='w'?>"; // Return the resulting XMP text return $output_XMP_text; }
function write_xml_array_to_text($xmlarray, $indentlevel) { // Create a string to receive the XML $output_xml_text = ""; // Cycle through each xml element at this level foreach ($xmlarray as $xml_elem) { // Add the indent, then the cleaned tag name to the output $output_xml_text .= str_repeat(" ", $indentlevel) . "<" . xml_UTF8_clean($xml_elem['tag']); // Check if there are any attributes for this tag if (array_key_exists('attributes', $xml_elem)) { // There are attributes // Cycle through each attribute for this tag foreach ($xml_elem['attributes'] as $xml_attr_name => $xml_attr_val) { // Add the cleaned attribute name, and cleaned attribute value to the output $output_xml_text .= " " . xml_UTF8_clean($xml_attr_name) . " ='" . xml_UTF8_clean($xml_attr_val) . "'"; } } // Add the 'greater-than' to close this tag to the output $output_xml_text .= ">"; // Check if this element has any text inside it. if (array_key_exists('value', $xml_elem)) { // There is text for this element - clean it and add it to the output $output_xml_text .= xml_UTF8_clean($xml_elem['value']); } // Check if there are any lower levels contained by this element if (array_key_exists('children', $xml_elem)) { // There are sub-elements for this element // Add a newline to the output, so the sub-elements start on a fresh line $output_xml_text .= "\n"; // Recursively call this function to output the sub-elements, and add the result to the output $output_xml_text .= write_xml_array_to_text($xml_elem['children'], $indentlevel + 1); // Add an indent to the output for the closing tag, since we are on a new line due to the sub-elements $output_xml_text .= str_repeat(" ", $indentlevel); } // Add the cleaned closing tag to the output $output_xml_text .= "</" . xml_UTF8_clean($xml_elem['tag']) . ">\n"; } // Return the XML text return $output_xml_text; }