Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
e6828006
Commit
e6828006
authored
Mar 03, 2005
by
Steven Wittens
Browse files
-
#18319
: Move encoding conversion out of drupal_xml_parser_create() so it can be used by modules.
parent
f7c8a2c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
e6828006
...
...
@@ -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'
;
...
...
@@ -1672,6 +1659,34 @@ function drupal_xml_parser_create(&$data) {
return
$xml_parser
;
}
/**
* 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.
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment