Search code examples
phplaravel-5encodingimap

PHP: how to decode a string having "=20" and "=A0"


I am using IMAP API to getting the emails from the gmail. But some email subjects are encoded like

=?utf-8?Q?We=20aren=27t=20fooling=20around=3A=20Up=20to=2050%=20off=20on=20Polo=27s=2C=20Swimwear=2C=20Jeans=20&=20More?=

I am not getting in which format it is encoded and how to decode it. The actual email subject is

We aren't fooling around: Up to 50% off on Polo's, Swimwear, Jeans & More

Solution

  • Use PHP predefine function

    iconv_mime_decode()

    <?php
       $str = "=?utf-8?Q?We=20aren=27t=20fooling=20around=3A=20Up=20to=2050%=20off=20on=20Polo=27s=2C=20Swimwear=2C=20Jeans=20&=20More?=";
        echo iconv_mime_decode($str);