summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2005-03-03 20:06:42 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2005-03-03 20:06:42 +0000
commite68280064ea55528359d6738d9942062b3d7d554 (patch)
tree872b3da3b4d040d15d75728d012fa21363350db6 /includes
parentf7c8a2c080e1339d73315d56107813d48afaa2d2 (diff)
downloadbrdo-e68280064ea55528359d6738d9942062b3d7d554.tar.gz
brdo-e68280064ea55528359d6738d9942062b3d7d554.tar.bz2
- #18319: Move encoding conversion out of drupal_xml_parser_create() so it can be used by modules.
Diffstat (limited to 'includes')
-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