<?php
|
|
/**
|
|
* Sxml.php
|
|
* utils of sxml.
|
|
* @version 150810:1
|
|
* @author karminski <code.karminski@outlook.com>
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* class Sxml
|
|
*/
|
|
class Sxml{
|
|
|
|
const SXML_ATOM_TMPL = '<%s:%s>';
|
|
|
|
/**
|
|
* [encryptSxml description]
|
|
* @param [type] &$data [description]
|
|
* @param string &$retval [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public static function encrypt(&$data, &$retval = ""){
|
|
foreach($data as $key => $value){
|
|
$retval .= sprintf(self::SXML_ATOM_TMPL, $key, $value);
|
|
}
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* [decryptSxml description]
|
|
* @param [type] $line [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public static function decrypt(&$line, &$retval = array()){
|
|
$stage1 = explode("><", $line);
|
|
$stage1Len = count($stage1);
|
|
// single field
|
|
if($stage1Len===1){
|
|
return false;
|
|
}
|
|
// multifield ok
|
|
foreach($stage1 as $serial => $subLine){
|
|
if($serial === 0){
|
|
$subLine = str_replace("<", "", $subLine);
|
|
}
|
|
if($serial === ($stage1Len-1)){
|
|
$subLine = str_replace(">", "", $subLine);
|
|
}
|
|
$stage2 = explode(":", $subLine);
|
|
$key = $stage2[0];
|
|
unset($stage2[0]);
|
|
$value = implode(":", $stage2); // avoide ":" in data
|
|
$retval[$key] = $value;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|