summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc43
1 files changed, 29 insertions, 14 deletions
diff --git a/includes/common.inc b/includes/common.inc
index e63271779..ce95baa39 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1643,20 +1643,7 @@ function drupal_xml_parser_create(&$data) {
// Requires the iconv, GNU recode or mbstring PHP extension.
$php_supported = array('utf-8', 'iso-8859-1', 'us-ascii');
if (!in_array(strtolower($encoding), $php_supported)) {
- 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 {
- watchdog('php', t("Unsupported XML encoding '%s'. Please install iconv, GNU recode or mbstring for PHP.", $encoding), WATCHDOG_ERROR);
- return 0;
- }
-
+ $out = drupal_convert_to_utf8($data, $encoding);
if ($out !== false) {
$data = $out;
$encoding = 'utf-8';
@@ -1673,6 +1660,34 @@ function drupal_xml_parser_create(&$data) {
}
/**
+ * Convert data to UTF-8
+ *
+ * @param $data
+ * The data to be converted.
+ * @param $encoding
+ * The encoding that the data is in
+ * @return
+ * Converted data or FALSE.
+ */
+function drupal_convert_to_utf8($data, $encoding) {
+ 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 {
+ watchdog('php', t("Unsupported encoding '%s'. Please install iconv, GNU recode or mbstring for PHP.", $encoding), WATCHDOG_ERROR);
+ return FALSE;
+ }
+
+ return $out;
+}
+
+/**
* Truncate a UTF-8-encoded string safely.
*
* If the end position is in the middle of a UTF-8 sequence, it scans backwards