1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12use Symfony\Polyfill\Iconv as p; 13 14if (!defined('ICONV_IMPL')) { 15 define('ICONV_IMPL', 'Symfony'); 16} 17if (!defined('ICONV_VERSION')) { 18 define('ICONV_VERSION', '1.0'); 19} 20if (!defined('ICONV_MIME_DECODE_STRICT')) { 21 define('ICONV_MIME_DECODE_STRICT', 1); 22} 23if (!defined('ICONV_MIME_DECODE_CONTINUE_ON_ERROR')) { 24 define('ICONV_MIME_DECODE_CONTINUE_ON_ERROR', 2); 25} 26 27if (!function_exists('iconv')) { 28 function iconv(?string $from_encoding, ?string $to_encoding, ?string $string): string|false { return p\Iconv::iconv((string) $from_encoding, (string) $to_encoding, (string) $string); } 29} 30if (!function_exists('iconv_get_encoding')) { 31 function iconv_get_encoding(?string $type = 'all'): array|string|false { return p\Iconv::iconv_get_encoding((string) $type); } 32} 33if (!function_exists('iconv_set_encoding')) { 34 function iconv_set_encoding(?string $type, ?string $encoding): bool { return p\Iconv::iconv_set_encoding((string) $type, (string) $encoding); } 35} 36if (!function_exists('iconv_mime_encode')) { 37 function iconv_mime_encode(?string $field_name, ?string $field_value, ?array $options = []): string|false { return p\Iconv::iconv_mime_encode((string) $field_name, (string) $field_value, (array) $options); } 38} 39if (!function_exists('iconv_mime_decode_headers')) { 40 function iconv_mime_decode_headers(?string $headers, ?int $mode = 0, ?string $encoding = null): array|false { return p\Iconv::iconv_mime_decode_headers((string) $headers, (int) $mode, $encoding); } 41} 42 43if (extension_loaded('mbstring')) { 44 if (!function_exists('iconv_strlen')) { 45 function iconv_strlen(?string $string, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strlen((string) $string, $encoding); } 46 } 47 if (!function_exists('iconv_strpos')) { 48 function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } 49 } 50 if (!function_exists('iconv_strrpos')) { 51 function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strrpos((string) $haystack, (string) $needle, 0, $encoding); } 52 } 53 if (!function_exists('iconv_substr')) { 54 function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_substr((string) $string, (int) $offset, $length, $encoding); } 55 } 56 if (!function_exists('iconv_mime_decode')) { 57 function iconv_mime_decode($string, $mode = 0, $encoding = null) { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_decode_mimeheader($string, $mode, $encoding); } 58 } 59} else { 60 if (!function_exists('iconv_strlen')) { 61 if (extension_loaded('xml')) { 62 function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen1((string) $string, $encoding); } 63 } else { 64 function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen2((string) $string, $encoding); } 65 } 66 } 67 68 if (!function_exists('iconv_strpos')) { 69 function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Iconv::iconv_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } 70 } 71 if (!function_exists('iconv_strrpos')) { 72 function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { return p\Iconv::iconv_strrpos((string) $haystack, (string) $needle, $encoding); } 73 } 74 if (!function_exists('iconv_substr')) { 75 function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { return p\Iconv::iconv_substr((string) $string, (string) $offset, $length, $encoding); } 76 } 77 if (!function_exists('iconv_mime_decode')) { 78 function iconv_mime_decode(?string $string, ?int $mode = 0, ?string $encoding = null): string|false { return p\Iconv::iconv_mime_decode((string) $string, (int) $mode, $encoding); } 79 } 80} 81