3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Stdlib\StringWrapper;
12 use Zend\Stdlib\Exception;
14 class Intl extends AbstractStringWrapper
17 * List of supported character sets (upper case)
21 protected static $encodings = ['UTF-8'];
24 * Get a list of supported character encodings
28 public static function getSupportedEncodings()
30 return static::$encodings;
36 * @throws Exception\ExtensionNotLoadedException
38 public function __construct()
40 if (! extension_loaded('intl')) {
41 throw new Exception\ExtensionNotLoadedException(
42 'PHP extension "intl" is required for this wrapper'
48 * Returns the length of the given string
53 public function strlen($str)
55 return grapheme_strlen($str);
59 * Returns the portion of string specified by the start and length parameters
63 * @param int|null $length
64 * @return string|false
66 public function substr($str, $offset = 0, $length = null)
68 // Due fix of PHP #62759 The third argument returns an empty string if is 0 or null.
69 if ($length !== null) {
70 return grapheme_substr($str, $offset, $length);
73 return grapheme_substr($str, $offset);
77 * Find the position of the first occurrence of a substring in a string
79 * @param string $haystack
80 * @param string $needle
84 public function strpos($haystack, $needle, $offset = 0)
86 return grapheme_strpos($haystack, $needle, $offset);