расшифровка кодировки

Discussion in 'PHP' started by Дикс, 22 Oct 2009.

  1. Дикс

    Дикс Elder - Старейшина

    Joined:
    16 Apr 2006
    Messages:
    1,194
    Likes Received:
    227
    Reputations:
    26
    попалось такое письмецо:

    PHP:
    $body "heardfroma,

    =D0=91=D0=BB=D0=B0=D0=B3=D0=BE=D0=B4=D0=B0=D1=80=D0=B8=D0=BC =D0=92=D0=B0=
    =D1=81 =D0=B7=D0=B0 =D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=
    =D0=B8=D1=8E =D0=BD=D0=B0 =D1=81=D0=B0=D0=B9=D1=82=D0=B5 =20
    =D0=9F=D0=BE=D0=BF=D1=83=D0=BB=D1=8F=D1=80=D0=B5=D0=BD.RU - =D1=81=D0=BE=D0=
    =BE=D0=B1=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=BE =D1=82=D0=B0=D0=BB=D0=B0=D0=
    =BD=D1=82=D0=BB=D0=B8=D0=B2=D1=8B=D1=85 =D0=B8 =20
    =D1=82=D0=B2=D0=BE=D1=80=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D1=85 =D0=BB=D1=8E=
    =D0=B4=D0=B5=D0=B9. =D0=92=D1=8B =D0=BC=D0=BE=D0=B6=D0=B5=D1=82=D0=B5 =D1=
    =81=D0=B5=D0=B9=D1=87=D0=B0=D1=81 =D0=B2=D0=BE=D0=B9=D1=82=D0=B8 =20
    =D0=BD=D0=B0 http://populyaren.ru/user =D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=
    =D0=B7=D1=83=D1=8F =D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B8=D0=B5=
     =20
    =D1=83=D1=87=D0=B5=D1=82=D0=BD=D1=8B=D0=B5 =D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=
    =D0=B5:

    =D0=B8=D0=BC=D1=8F =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=
    =D0=B5=D0=BB=D1=8F: heardfroma
    =D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C: 9gc4d09

    =D0=92=D1=8B =D1=82=D0=B0=D0=BA =D0=B6=D0=B5 =D0=BC=D0=BE=D0=B6=D0=B5=D1=82=
    =D0=B5 =D0=B2=D0=BE=D0=B9=D1=82=D0=B8, =D0=BD=D0=B0=D0=B6=D0=B0=D0=B2 =D0=
    =BD=D0=B0 =D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D1=83=D1=8E =20
    =D1=81=D1=81=D1=8B=D0=BB=D0=BA=D1=83 =D0=B8=D0=BB=D0=B8 =D1=81=D0=BA=D0=BE=
    =D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=B2 =D0=B5=D1=91 =D0=B2 =D0=B0=D0=B4=
    =D1=80=D0=B5=D1=81=D0=BD=D1=83=D1=8E =20
    =D1=81=D1=82=D1=80=D0=BE=D0=BA=D1=83 =D0=B1=D1=80=D0=B0=D1=83=D0=B7=D0=B5=
    =D1=80=D0=B0:

    http://populyaren.ru/user/reset/6/125621159d0/37d8610587d6bba111ab231f470f3=
    09f5

    =D0=AD=D1=82=D0=BE =D0=BE=D0=B4=D0=BD=D0=BE=D1=80=D0=B0=D0=B7=D0=BE=D0=B2=
    =D1=8B=D0=B9 =D0=B2=D1=85=D0=BE=D0=B4 =D0=B8 =D0=B2=D0=BE=D1=81=D0=BF=D0=BE=
    =D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=D1=81=D1=8F =D0=B8=D0=BC=
     =20
    =D0=BC=D0=BE=D0=B6=D0=BD=D0=BE =D0=BB=D0=B8=D1=88=D1=8C =D0=BE=D0=B4=D0=BD=
    =D0=B0=D0=B6=D0=B4=D1=8B. =D0=9F=D0=BE=D1=81=D0=BB=D0=B5 =D0=B2=D1=85=D0=BE=
    =D0=B4=D0=B0 =D0=BD=D0=B0 =D1=81=D0=B0=D0=B9=D1=82 =D0=B2=D1=8B =20
    =D0=B1=D1=83=D0=B4=D0=B5=D1=82=D0=B5 =D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B0=
    =D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B =D0=BD=D0=B0 =D1=81=D1=82=
    =D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=83 =20
    http://populyaren.ru/user/6/edit, =D0=B3=D0=B4=D0=B5 =D0=BC=D0=BE=D0=B6=D0=
    =B5=D1=82=D0=B5 =D1=81=D0=BC=D0=B5=D0=BD=D0=B8=D1=82=D1=8C =D1=81=D0=B2=D0=
    =BE=D0=B9 =20
    =D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C.


    =D0=A1 =D1=83=D0=B2=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC =D0=BA =D0=92=
    =D0=B0=D0=BC heardfroma, =D0=90=D0=B4=D0=BC=D0=B8=D0=BD=D0=B8=D1=81=D1=82=
    =D1=80=D0=B0=D1=82=D0=BE=D1=80 =20
    =D0=9F=D0=BE=D0=BF=D1=83=D0=BB=D1=8F=D1=80=D0=B5=D0=BD.=D0=A0=D1=83"
    ;
    решил таким извратом:

    PHP:
    $var explode('<br />'nl2br($body));
    $new = array();

    foreach(
    $var as $line)
            
    $new[] = (substr($line, -1) == '=')? substr(trim($line), 0, -1) : trim($line);

    $body mb_convert_encoding(urldecode(str_replace('=''%'implode(''$new))), 'utf-8''auto');
    а есть способ попроще?
     
  2. Kaimi

    Kaimi Well-Known Member

    Joined:
    23 Aug 2007
    Messages:
    1,732
    Likes Received:
    811
    Reputations:
    231
    PHP:
    <?php
    print urldecode(str_replace(Array("=\r\n",'=','_'),Array('','%',' '),$body));
    ?>
     
    _________________________
    2 people like this.
  3. Дикс

    Дикс Elder - Старейшина

    Joined:
    16 Apr 2006
    Messages:
    1,194
    Likes Received:
    227
    Reputations:
    26
    а зачем удалять _ ?

    и тогда наверное так будет правильнее:

    PHP:
    print urldecode(str_replace(Array("=" PHP_EOL,'=','_'),Array('','%',' '),$body));
     
  4. krypt3r

    krypt3r Elder - Старейшина

    Joined:
    27 Apr 2007
    Messages:
    1,507
    Likes Received:
    389
    Reputations:
    101
    PHP:
    preg_replace ('/=([A-F0-9]{2})/e''chr(0x\\1)'$body);
     
  5. Дикс

    Дикс Elder - Старейшина

    Joined:
    16 Apr 2006
    Messages:
    1,194
    Likes Received:
    227
    Reputations:
    26
    классно!

    осталось только узнать, что это вообще такое:
    и почему пхп это не понимает
     
  6. Kaimi

    Kaimi Well-Known Member

    Joined:
    23 Aug 2007
    Messages:
    1,732
    Likes Received:
    811
    Reputations:
    231
    http://en.wikipedia.org/wiki/Quoted-printable
     
    _________________________
  7. krypt3r

    krypt3r Elder - Старейшина

    Joined:
    27 Apr 2007
    Messages:
    1,507
    Likes Received:
    389
    Reputations:
    101
    тогда все еще проще
    PHP:
    quoted_printable_decode()
    Если не ошибаюсь, среди функций imap_* есть похожая, не помню точно, как называется
     
    #7 krypt3r, 22 Oct 2009
    Last edited: 22 Oct 2009
    1 person likes this.
  8. Zver@

    Zver@ Banned

    Joined:
    3 Sep 2011
    Messages:
    7
    Likes Received:
    0
    Reputations:
    0
    Помогите пожалуйста

    %D0%B4%D0%BC%D0%B0%D0%BF%D0%B4%D0%B3%D0%B0%D0%B4%D0%B0&sourceid
     
  9. Kaimi

    Kaimi Well-Known Member

    Joined:
    23 Aug 2007
    Messages:
    1,732
    Likes Received:
    811
    Reputations:
    231
    http://php.net/manual/en/function.urldecode.php
     
    _________________________