Open robinvdvleuten opened 10 years ago
The following (basic) code works:
$yEncodedString = 'ybegin**** (yencoded string ******)';
$encoded = array();
// Extract the yEnc string itself.
preg_match("/^(=ybegin.*=yend[^$]*)$/ims", $yEncodedString, $encoded);
if (!isset($encoded[1])) {
return false;
}
$encoded = $encoded[1];
// Remove the header and trailer from the string before parsing it.
$encoded = preg_replace("/(^=ybegin.*\\r\\n)/im", "", $encoded, 1);
$encoded = preg_replace("/(^=ypart.*\\r\\n)/im", "", $encoded, 1);
$encoded = preg_replace("/(^=yend.*)/im", "", $encoded, 1);
// Remove linebreaks from the string.
$encoded = trim(str_replace("\r\n", "", $encoded));
// Decode
$decoded = '';
for( $i = 0; $i < strlen($encoded); $i++)
{
if ($encoded{$i} == "=")
{
$i++;
$decoded .= chr((ord($encoded{$i}) - 64) - 42);
}
else
{
$decoded .= chr(ord($encoded{$i}) - 42);
}
}
// Do something with the $decoded
@kissifrot can you create a PR for this functionality?
Add support for yenc encoded overviews