Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
MbString.php
001 <?php
002 /**
003 * Zend Framework (http://framework.zend.com/)
004 *
005 * @link http://github.com/zendframework/zf2 for the canonical source repository
006 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007 * @license http://framework.zend.com/license/new-bsd New BSD License
008 */
009
010 namespace Zend\Stdlib\StringWrapper;
011
012 use Zend\Stdlib\Exception;
013
014 class MbString extends AbstractStringWrapper
015 {
016 /**
017 * List of supported character sets (upper case)
018 *
019 * @var null|string[]
020 * @link http://php.net/manual/mbstring.supported-encodings.php
021 */
022 protected static $encodings = null;
023
024 /**
025 * Get a list of supported character encodings
026 *
027 * @return string[]
028 */
029 public static function getSupportedEncodings()
030 {
031 if (static::$encodings === null) {
032 static::$encodings = array_map('strtoupper', mb_list_encodings());
033
034 // FIXME: Converting € (UTF-8) to ISO-8859-16 gives a wrong result
035 $indexIso885916 = array_search('ISO-8859-16', static::$encodings, true);
036 if ($indexIso885916 !== false) {
037 unset(static::$encodings[$indexIso885916]);
038 }
039 }
040
041 return static::$encodings;
042 }
043
044 /**
045 * Constructor
046 *
047 * @throws Exception\ExtensionNotLoadedException
048 */
049 public function __construct()
050 {
051 if (!extension_loaded('mbstring')) {
052 throw new Exception\ExtensionNotLoadedException(
053 'PHP extension "mbstring" is required for this wrapper'
054 );
055 }
056 }
057
058 /**
059 * Returns the length of the given string
060 *
061 * @param string $str
062 * @return int|false
063 */
064 public function strlen($str)
065 {
066 return mb_strlen($str, $this->getEncoding());
067 }
068
069 /**
070 * Returns the portion of string specified by the start and length parameters
071 *
072 * @param string $str
073 * @param int $offset
074 * @param int|null $length
075 * @return string|false
076 */
077 public function substr($str, $offset = 0, $length = null)
078 {
079 return mb_substr($str, $offset, $length, $this->getEncoding());
080 }
081
082 /**
083 * Find the position of the first occurrence of a substring in a string
084 *
085 * @param string $haystack
086 * @param string $needle
087 * @param int $offset
088 * @return int|false
089 */
090 public function strpos($haystack, $needle, $offset = 0)
091 {
092 return mb_strpos($haystack, $needle, $offset, $this->getEncoding());
093 }
094
095 /**
096 * Convert a string from defined encoding to the defined convert encoding
097 *
098 * @param string $str
099 * @param bool $reverse
100 * @return string|false
101 */
102 public function convert($str, $reverse = false)
103 {
104 $encoding = $this->getEncoding();
105 $convertEncoding = $this->getConvertEncoding();
106
107 if ($convertEncoding === null) {
108 throw new Exception\LogicException(
109 'No convert encoding defined'
110 );
111 }
112
113 if ($encoding === $convertEncoding) {
114 return $str;
115 }
116
117 $fromEncoding = $reverse ? $convertEncoding : $encoding;
118 $toEncoding = $reverse ? $encoding : $convertEncoding;
119 return mb_convert_encoding($str, $toEncoding, $fromEncoding);
120 }
121 }
122