Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getPropertyFromPhpInfo($pattern)
- {
- ob_start();
- phpinfo();
- $phpinfo = ob_get_clean();
- $result = preg_match($pattern, $phpinfo, $matches);
- if ($result !== 1) {
- return null;
- }
- return $matches[0];
- }
- function getIconvEncodings()
- {
- $encodings = shell_exec('/usr/bin/iconv --list');
- $encodings = strtolower(trim($encodings));
- $encodings = str_replace('//', '', $encodings);
- $encodings = preg_split('/\s+/', $encodings);
- return $encodings;
- }
- function getMbstringEncodings()
- {
- $encodings = mb_list_encodings();
- $encodings = array_map('strtolower', $encodings);
- return $encodings;
- }
- function makeTableRow($encoding, $iconv, $mbstring)
- {
- $output = sprintf('%20s', $encoding) . ' ';
- $output .= sprintf('%-5s', $iconv ) . ' ';
- $output .= sprintf('%-5s', $mbstring) . PHP_EOL;
- return $output;
- }
- error_reporting(E_ALL & ~E_NOTICE);
- date_default_timezone_set('UTC');
- echo getPropertyFromPhpInfo('/PHP Version => [0-9.]+/' ) . PHP_EOL;
- echo getPropertyFromPhpInfo('/Multibyte string engine => [a-z]+/') . PHP_EOL;
- echo getPropertyFromPhpInfo('/libmbfl version => [0-9.]+/' ) . PHP_EOL;
- echo getPropertyFromPhpInfo('/iconv implementation => [a-z]+/' ) . PHP_EOL;
- echo getPropertyFromPhpInfo('/iconv library version => [0-9.]+/' ) . PHP_EOL . PHP_EOL;
- $encodings = [
- 'iconv' => getIconvEncodings(),
- 'mbstring' => getMbstringEncodings()
- ];
- foreach ($encodings as $lib => $encs) {
- echo $lib . ' encodings:' . PHP_EOL;
- print_r($encs);
- echo PHP_EOL;
- }
- $commonEncodings = array_intersect($encodings['iconv'], $encodings['mbstring']);
- sort($commonEncodings);
- define('TOTAL_BYTES', 1000);
- $data = openssl_random_pseudo_bytes(TOTAL_BYTES);
- echo 'Common encodings, with calculated lengths for ' . TOTAL_BYTES . ' bytes:' . PHP_EOL;
- echo makeTableRow('ENCODING', 'ICONV', 'MBSTRING');
- foreach ($commonEncodings as $encoding) {
- echo makeTableRow(
- $encoding,
- iconv_strlen($data, $encoding . '//IGNORE'), // From Patchwork\PHP\Shim\Mbstring
- mb_strlen($data, $encoding)
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement