public convert_text ( $text ) |
function convert_text($text)
{
global $debugObject;
if (is_object($debugObject)) {
$debugObject->debugLogEntry(1);
}
$converted_text = $text;
$sourceCharset = "";
$targetCharset = "";
if ($this->dom) {
$sourceCharset = strtoupper($this->dom->_charset);
$targetCharset = strtoupper($this->dom->_target_charset);
}
if (is_object($debugObject)) {
$debugObject->debugLog(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);
}
if (!empty($sourceCharset) && !empty($targetCharset) && strcasecmp($sourceCharset, $targetCharset) != 0) {
// Check if the reported encoding could have been incorrect and the text is actually already UTF-8
if (strcasecmp($targetCharset, 'UTF-8') == 0 && $this->is_utf8($text)) {
$converted_text = $text;
} else {
$converted_text = iconv($sourceCharset, $targetCharset, $text);
}
}
// Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
if ($targetCharset == 'UTF-8') {
if (substr($converted_text, 0, 3) == "") {
$converted_text = substr($converted_text, 3);
}
if (substr($converted_text, -3) == "") {
$converted_text = substr($converted_text, 0, -3);
}
}
return $converted_text;
}