64base encoded XML

Associate
Joined
18 Oct 2002
Posts
100
Hi

Wonder if someone could help
I have an 64base encoded XML file that I need to decode

There are 100's of products example below

Need to keep the XML as XML format & simply decode the data

I know a bit of php but I'm stuck on this :(

Is there a PHP fuction that will sort this out

Code:
<productdescription>
  <product>
   	   <item_price>MTkuOTk=</item_price>
    <item_code>U1NUNjY3OA==</item_code>
    <item_weight>Mg==</item_weight>
    <item_title>VGhlIExvc3QgU3ltYm9sIChIYXJkY292ZXIp</item_title>
    <item_category>Ym9va3M=</item_category>
    <productid>MzY1NjI3</productid>
    <manufacturer>RGFuIEJyb3du</manufacturer>
    <manuf_code>MDU5MzA1NDI3WA==</manuf_code>
    <item_on_order_qty>MA==</item_on_order_qty>
    <item_virtual_qty>MA==</item_virtual_qty>
    <item_virtual_message></item_virtual_message>
    <item_image>aHR0cDovL2VjeC5pbWFnZXMtYW1hem9uLmNvbS9pbWFnZXMvSS80MUdCWUZhM1hBTC5fU0w1MDBfQUEyNDBfLmpwZw==</item_image>
  </product>
  <attributes>
    <element>
      <Marketing>VGhlIExvc3QgU3ltYm9sIChIYXJkY292ZXIp</Marketing>
    </element>
  </attributes>
  <specification>
    <spec_element>
      <spec_title>Ym9vaw==</spec_title>
      <spec_description>Ym9vaw==</spec_description>

      <spec_value>YW5vdGhlciBib29r</spec_value>
    </spec_element>
    <spec_element>
      <spec_title>Ym9vaw==</spec_title>
      <spec_description>UGFja2FnZQ==</spec_description>
      <spec_value>dHlwZQ==</spec_value>
    </spec_element>
    <spec_element>
      <spec_title>Ym9vaw==</spec_title>
      <spec_description>VGVjaG5vbG9neQ==</spec_description>
      <spec_value>NDVtbQ==</spec_value>
    </spec_element>
    <spec_element>
      <spec_title>UGh5c2ljYWw=</spec_title>
      <spec_description>Y29sb3Vy</spec_description>
      <spec_value>UmVk</spec_value>
    </spec_element>
  </specification>
</productdescription>
 
PHP:
<?php
// Read XML file
$xml = file_get_contents("slasher.xml");

// Hacked from from
// http://www.webdeveloper.com/forum/archive/index.php/t-68389.html
$result = preg_replace_callback('/(\w+)(=?)(=?)(?![^<]*>)/', "decode", $xml);

// Output
echo htmlentities($result);

// Called above in preg_replace_callback for each match, decodes the base64
// and returns it
function decode($matches)
{
	return base64_decode($matches[0]);
}

I know that regex is horrid, and probably doesn't match everything it should. I've never used it before as I've always considered it pure evil :p, but it seems to work on the above example anyway:

slasher.png

A Big Big thank you
Your a star - Works perfect many many thanks :)
 
One final question is there a way of integrating this to rewrite the XML instead of just returning the decoded data?

Many thanks in advance

Regards

Dave
 
Back
Top Bottom