simple_html_dom_node::convert_text PHP Method

convert_text() public method

PaperG - Function to convert the text from one character set to another if the two sets are not the same.
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);
            }
        }
        return $converted_text;
    }