2 // @generated by docskel.php
4 <<__NativeData("UConverter")>>
7 * Create UConverter object
9 * @param string $destination_encoding -
10 * @param string $source_encoding -
15 public function __construct(string $destination_encoding = 'utf-8',
16 string $source_encoding = 'utf-8'): void
;
19 * Convert string from one charset to another
21 * @param string $str -
22 * @param bool $reverse -
27 public function convert(string $str,
28 bool $reverse = false): mixed;
31 * Default "from" callback function
33 * @param int $reason -
34 * @param string $source -
35 * @param string $codePoint -
40 public function fromUCallback(int $reason,
45 case self
::REASON_UNASSIGNED
:
46 case self
::REASON_ILLEGAL
:
47 case self
::REASON_IRREGULAR
:
48 $error = U_ZERO_ERROR
;
49 return $this->getDestinationSubstChars();
55 * Get the aliases of the given name
57 * @param string $name -
62 public static function getAliases(string $name): mixed;
65 * Get the available canonical converter names
70 public static function getAvailable(): array;
73 * Get the destination encoding
78 public function getDestinationEncoding(): string;
81 * Get the destination converter type
86 public function getDestinationType(): int;
89 * Get last error code on the object
94 public function getErrorCode(): int;
97 * Get last error message on the object
102 public function getErrorMessage(): string;
105 * Get the source encoding
110 public function getSourceEncoding(): string;
113 * Get the source convertor type
118 public function getSourceType(): int;
126 public static function getStandardName(string $name,
127 string $standard): mixed;
134 public static function getMimeName(string $name): mixed {
135 return self
::getStandardName($name, "MIME");
139 * Get standards associated to converter names
144 public static function getStandards(): mixed;
147 * Get substitution chars
152 public function getDestinationSubstChars(): mixed;
155 * Get substitution chars
160 public function getSourceSubstChars(): mixed;
163 * Get substitution chars
167 public function getSubstChars(): mixed {
168 // Ambiguous, but mostly PHP compat
169 // since PHP version lacks distinct setters
170 return $this->getSourceSubstChars();
174 * Get string representation of the callback reason
176 * @param int $reason -
181 public static function reasonText(int $reason): mixed;
184 * Set the destination encoding
186 * @param string $encoding -
191 public function setDestinationEncoding(string $encoding): void
;
194 * Set the source encoding
196 * @param string $encoding -
201 public function setSourceEncoding(string $encoding): bool;
204 * Set the substitution chars
206 * @param string $chars -
211 public function setDestinationSubstChars(string $chars): bool;
214 * Set the destination substitution chars
216 * @param string $chars -
221 public function setSourceSubstChars(string $chars): bool;
224 * Set the substitution chars
226 * @param string $chars -
230 public function setSubstChars(string $chars): bool {
231 return $this->setSourceSubstChars($chars) &&
232 $this->setDestinationSubstChars($chars);
236 * Default "to" callback function
238 * @param int $reason -
239 * @param string $source -
240 * @param string $codeUnits -
241 * @param int $error -
245 public function toUCallback(int $reason,
248 int &$error): mixed {
250 case self
::REASON_UNASSIGNED
:
251 case self
::REASON_ILLEGAL
:
252 case self
::REASON_IRREGULAR
:
253 $error = U_ZERO_ERROR
;
254 return $this->getSourceSubstChars();
260 * Convert string from one charset to another
262 * @param string $str -
263 * @param string $toEncoding -
264 * @param string $fromEncoding -
265 * @param array $options -
269 public static function transcode(string $str,
271 string $fromEncoding,
272 array $options = null): ?
string {
273 $cnv = new UConverter($toEncoding, $fromEncoding);
274 if ((isset($options['from_subst']) &&
275 !$cnv->setSourceSubstChars($options['from_subst'])) ||
276 (isset($options['to_subst']) &&
277 !$cnv->setDestinationSubstChars($options['to_subst']))) {
280 return $cnv->convert($str);