[drupal-devel] Email filter

Tim Altman web at timaltman.com
Sun Mar 13 13:20:28 UTC 2005


Mark Leicester said:

[...]

> I'm using cvs 4.6 for this site. If the original email was iso-8859-1,
> then can just call drupal_convert_to_utf8($node->body, "ISO-8859-1")?
> It doesn't seem to be working for me: I get an empty string back. I'll
> double check.

That probably means that your PHP install doesn't support any of the
functions drupal_convert_to_utf8() supports.  For a 4.5.2 project, I'm
using the following function based on drupal_convert_to_utf8():

// everything needs to be in UTF-8
  function utf8_me($data, $encoding = "ISO-8859-1") {
    if (function_exists('iconv')) {
      $out = @iconv($encoding, 'utf-8', $data);
    }
    else if (function_exists('mb_convert_encoding')) {
      $out = @mb_convert_encoding($data, 'utf-8', $encoding);
    }
    else if (function_exists('recode_string')) {
     $out = @recode_string($encoding . '..utf-8', $data);
    }
    else if ((function_exists('utf8_encode')) && ($encoding ==
"ISO-8859-1")) {
     $out = @utf8_encode($data);
    }

    return $out;
  }

It has an added check for utf8_encode(), a standard PHP function. 
Unfortunately, utf8_encode() only works with ISO-8859-1.

I can roll a patch for drupal_convert_to_utf8() if anyone wants this is core.

-- 
Tim Altman



More information about the drupal-devel mailing list