Comment puis-je récupérer les valeurs recueillies par ce code :
<?
class BEncoderException extends Exception {}
class BEncoder
{
public $source;
public $encoded;
private $_offset = 0;
private $_len = 0;
public function decode ($str = null)
{
$this->source = array ();
if (!is_null ($str)) $this->encoded = $str;
$this->_offset = 0;
$this->_len = strlen ($this->encoded);
$this->source = $this->_decode ();
return $this->source;
}
public function encode ($value = null)
{
$this->encoded = '';
if (!is_null ($value)) $this->source = $value;
$this->encoded = $this->_encode ($this->source);
return $this->encoded;
}
private function _decodeInt ()
{
$end = strpos ($this->encoded, 'e', $this->_offset);
if ($end === false) throw new BEncoderException ('Decoding error at: ' . $this->_offset);
$result = (double) substr ($this->encoded, $this->_offset + 1, $end - $this->_offset - 1);
$this->_offset = $end + 1;
return $result;
}
private function _decodeString ()
{
$divider = strpos ($this->encoded, ':', $this->_offset);
if ($divider === false) throw new BEncoderException ('Decoding error at: ' . $this->_offset);
$len = (int) substr ($this->encoded, $this->_offset, $divider - $this->_offset);
$result = substr ($this->encoded, $divider + 1, $len);
$this->_offset = $divider + $len + 1;
return $result;
}
private function _decodeDictionary ()
{
$result = array ();
$this->_offset ++;
while ($this->encoded [$this->_offset] != 'e' && $this->_offset < $this->_len)
$result [$this->_decodeString ()] = $this->_decode ();
$this->_offset ++;
return $result;
}
private function _decodeList ()
{
$result = array ();
$this->_offset ++;
while ($this->encoded [$this->_offset] != 'e' && $this->_offset < $this->_len)
$result [] = $this->_decode ();
$this->_offset ++;
return $result;
}
private function _decode ()
{
switch ($this->encoded [$this->_offset])
{
case 'd':
return $this->_decodeDictionary ();
case 'i':
return $this->_decodeInt ();
case 'l':
return $this->_decodeList ();
}
if (is_numeric ($this->encoded [$this->_offset])) return $this->_decodeString ();
throw new BEncoderException ('Undefined data type at: ' . $this->_offset . ' while decoding');
}
private function _encodeString ($value)
{
return strlen ($value) . ':' . $value;
}
private function _encodeArray ($value)
{
$count = count ($value);
$list = true;
for ($i = 0; $i < $count; $i ++)
if (!isset ($value [$i]))
{
$list = false;
break;
}
ksort ($value);
return $list ? $this->_encodeList ($value) : $this->_encodeDictionary ($value);
}
private function _encodeList ($value)
{
$result = 'l';
foreach ($value as $item)
$result .= $this->_encode ($item);
return $result . 'e';
}
private function _encodeDictionary ($value)
{
$result = 'd';
foreach ($value as $key => $item)
$result .= $this->_encodeString ($key) . $this->_encode ($item);
return $result . 'e';
}
private function _encodeInt ($value)
{
return 'i' . ($value < 0 ? ceil ($value) : floor ($value)) . 'e';
}
private function _encode ($value)
{
switch (gettype ($value))
{
case 'NULL':
return '0:';
case 'string':
return $this->_encodeString ($value);
case 'array':
return $this->_encodeArray ($value);
case 'object':
return $this->_encodeArray (get_object_vars ($value));
case 'boolean':
return $this->_encodeInt ((int) $value);
case 'integer':
case 'double':
case 'float':
return $this->_encodeInt ($value);
default:
throw new BEncoderException ('Unknown datatype while encoding');
}
}
}
?
je désire recueillir les valeurs chacune dans une variable exploitable.
Merci de votre aide