PHP code to unescape data retrieved from a bytea column

Поиск
Список
Период
Сортировка
От huongch@bigfoot.com (Flancer)
Тема PHP code to unescape data retrieved from a bytea column
Дата
Msg-id 8c8c68a1.0110240118.441559a@posting.google.com
обсуждение исходный текст
Ответы Re: PHP code to unescape data retrieved from a bytea column
Список pgsql-general
To those who has been asking for it.. here it is.. pieced it togather
within a few hours so please excuse my clumsy syntaxes or algorithm or
my speed (for those who can actually code it a lot faster.... erm then
again I guess you won't be reading this post anyway).

function checkalphanum($ct,$i)
{
    //find if next 3 characters are digits or not
    for ($digitcount=0,$j = $i+1,$actual_count=1; ($actual_count <= 3) &&
($j < strlen($ct));++$actual_count, ++$j)
    {
        if ((ord($ct[$j]) >= 48) && (ord($ct[$j]) <= 57))
        {
            ++$digitcount;
        }
    }
    return $digitcount;
}

function unescape($ct,$i)
{
    $buff = "";
    for ($j = $i,$actual_count=1; ($actual_count <= 3) && ($j <
strlen($ct));++$actual_count, ++$j)
    {
             $buff .= $ct[$j];
    }
    return chr(octdec(intval($buff)));
}

function decode($ct)
{
 $buf = "";
 for ($i = 0; $i < strlen($ct); $i++)
 {
  if ($ct[$i] == "\\")
  {
   if ($ct[$i + 1] == "\\")
   {
     if (checkalphanum($ct,$i+1) == 3)
     {
         $i +=2;
         $buf .= unescape($ct,$i);
         $i +=2;
     }
     else
     {
         $buf .=$ct[$i];
     }
   }
   else
   {
    if (checkalphanum($ct,$i) == 3)
    {
        ++$i;
        $buf .= unescape($ct,$i);
        $i +=2;
    }
   }
  }
  else
  {
   $buf .= $ct[$i];
  }
 }
 return $buf;
}

I have tested it using data compressed using the bzcompress.. and
voila it bzdecompres perfectly using my function ;).
To use it just call something like

print decode($rawdatafrombytea);

So far I have only tested on data that was encoded using another PHP
function done by Joe Conway.

You can find that code here

http://groups.google.com/groups?q=bytea&hl=ms&group=comp.databases.postgresql.general&rnum=7&selm=027601c12c08%2454576a20%2448d210ac%40jecw2k1

If anyone out there can improve this code or already has a better
code.. please let me know ;).

В списке pgsql-general по дате отправления:

Предыдущее
От: jmsz@wespine.com.au (James Szabadics)
Дата:
Сообщение: Installation problems
Следующее
От: qk22@gmx.co.uk (qk22)
Дата:
Сообщение: Re: Can not input large text data