convertString() public static method

Converts encoding of text according to parameters with detected conversion function.
public static convertString ( string $src_charset, string $dest_charset, string $what ) : string
$src_charset string source charset
$dest_charset string target charset
$what string what to convert
return string converted text
Example #1
0
 public function testMbstring()
 {
     if (!@function_exists('mb_convert_encoding')) {
         $this->markTestSkipped('mbstring extension missing');
     }
     Encoding::setEngine(Encoding::ENGINE_MB);
     $this->assertEquals("This is the Euro symbol '?'.", Encoding::convertString('UTF-8', 'ISO-8859-1', "This is the Euro symbol '€'."));
 }
Example #2
0
 } while (false);
 // End of fake loop
 if ($save_on_server && !empty($message)) {
     PMA_showExportPage($db, $table, $export_type);
 }
 /**
  * Send the dump as a file...
  */
 if (empty($asfile)) {
     echo PMA_getHtmlForDisplayedExportFooter($back_button);
     return;
 }
 // end if
 // Convert the charset if required.
 if ($output_charset_conversion) {
     $dump_buffer = Encoding::convertString('utf-8', $GLOBALS['charset'], $dump_buffer);
 }
 // Compression needed?
 if ($compression) {
     if (!empty($separate_files)) {
         $dump_buffer = PMA_compressExport($dump_buffer_objects, $compression, $filename);
     } else {
         $dump_buffer = PMA_compressExport($dump_buffer, $compression, $filename);
     }
 }
 /* If we saved on server, we have to close file now */
 if ($save_on_server) {
     $message = PMA_closeExportFile($file_handle, $dump_buffer, $save_filename);
     PMA_showExportPage($db, $table, $export_type);
 } else {
     echo $dump_buffer;
Example #3
0
/**
 * Returns next part of imported file/buffer
 *
 * @param int $size size of buffer to read
 *                  (this is maximal size function will return)
 *
 * @return string part of file/buffer
 * @access public
 */
function PMA_importGetNextChunk($size = 32768)
{
    global $compression, $import_handle, $charset_conversion, $charset_of_file, $read_multiply;
    // Add some progression while reading large amount of data
    if ($read_multiply <= 8) {
        $size *= $read_multiply;
    } else {
        $size *= 8;
    }
    $read_multiply++;
    // We can not read too much
    if ($size > $GLOBALS['read_limit']) {
        $size = $GLOBALS['read_limit'];
    }
    if (PMA_checkTimeout()) {
        return false;
    }
    if ($GLOBALS['finished']) {
        return true;
    }
    if ($GLOBALS['import_file'] == 'none') {
        // Well this is not yet supported and tested,
        // but should return content of textarea
        if (mb_strlen($GLOBALS['import_text']) < $size) {
            $GLOBALS['finished'] = true;
            return $GLOBALS['import_text'];
        } else {
            $r = mb_substr($GLOBALS['import_text'], 0, $size);
            $GLOBALS['offset'] += $size;
            $GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size);
            return $r;
        }
    }
    $result = $import_handle->read($size);
    $GLOBALS['finished'] = $import_handle->eof();
    $GLOBALS['offset'] += $size;
    if ($charset_conversion) {
        return Encoding::convertString($charset_of_file, 'utf-8', $result);
    }
    /**
     * Skip possible byte order marks (I do not think we need more
     * charsets, but feel free to add more, you can use wikipedia for
     * reference: <https://en.wikipedia.org/wiki/Byte_Order_Mark>)
     *
     * @todo BOM could be used for charset autodetection
     */
    if ($GLOBALS['offset'] == $size) {
        // UTF-8
        if (strncmp($result, "", 3) == 0) {
            $result = mb_substr($result, 3);
            // UTF-16 BE, LE
        } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) {
            $result = mb_substr($result, 2);
        }
    }
    return $result;
}
Example #4
0
/**
 * Output handler for all exports, if needed buffering, it stores data into
 * $dump_buffer, otherwise it prints them out.
 *
 * @param string $line the insert statement
 *
 * @return bool Whether output succeeded
 */
function PMA_exportOutputHandler($line)
{
    global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
    // Kanji encoding convert feature
    if ($GLOBALS['output_kanji_conversion']) {
        $line = Encoding::kanjiStrConv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
    }
    // If we have to buffer data, we will perform everything at once at the end
    if ($GLOBALS['buffer_needed']) {
        $dump_buffer .= $line;
        if ($GLOBALS['onfly_compression']) {
            $dump_buffer_len += strlen($line);
            if ($dump_buffer_len > $GLOBALS['memory_limit']) {
                if ($GLOBALS['output_charset_conversion']) {
                    $dump_buffer = Encoding::convertString('utf-8', $GLOBALS['charset'], $dump_buffer);
                }
                if ($GLOBALS['compression'] == 'gzip' && PMA_gzencodeNeeded()) {
                    // as a gzipped file
                    // without the optional parameter level because it bugs
                    $dump_buffer = gzencode($dump_buffer);
                }
                if ($GLOBALS['save_on_server']) {
                    $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
                    // Here, use strlen rather than mb_strlen to get the length
                    // in bytes to compare against the number of bytes written.
                    if ($write_result != strlen($dump_buffer)) {
                        $GLOBALS['message'] = Message::error(__('Insufficient space to save the file %s.'));
                        $GLOBALS['message']->addParam($save_filename);
                        return false;
                    }
                } else {
                    echo $dump_buffer;
                }
                $dump_buffer = '';
                $dump_buffer_len = 0;
            }
        } else {
            $time_now = time();
            if ($time_start >= $time_now + 30) {
                $time_start = $time_now;
                header('X-pmaPing: Pong');
            }
            // end if
        }
    } else {
        if ($GLOBALS['asfile']) {
            if ($GLOBALS['output_charset_conversion']) {
                $line = Encoding::convertString('utf-8', $GLOBALS['charset'], $line);
            }
            if ($GLOBALS['save_on_server'] && mb_strlen($line) > 0) {
                $write_result = @fwrite($GLOBALS['file_handle'], $line);
                // Here, use strlen rather than mb_strlen to get the length
                // in bytes to compare against the number of bytes written.
                if (!$write_result || $write_result != strlen($line)) {
                    $GLOBALS['message'] = Message::error(__('Insufficient space to save the file %s.'));
                    $GLOBALS['message']->addParam($save_filename);
                    return false;
                }
                $time_now = time();
                if ($time_start >= $time_now + 30) {
                    $time_start = $time_now;
                    header('X-pmaPing: Pong');
                }
                // end if
            } else {
                // We export as file - output normally
                echo $line;
            }
        } else {
            // We export as html - replace special chars
            echo htmlspecialchars($line);
        }
    }
    return true;
}