/** * intl * @link http://php.net/manual/en/uconverter.convert.php * * @return string|false */ public function intl() { try { $uConverter = new \UConverter(self::ENCODING, $this->encoding); $converted = $uConverter->convert($this->string); } catch (\Exception $e) { return false; } return $converted; }
<?php $c = new UConverter('utf-8', 'latin1'); var_dump(UConverter::LATIN_1 === $c->getSourceType()); var_dump(UConverter::UTF8 === $c->getDestinationType()); $c = new UConverter('koi8-r', 'utf-32be'); var_dump(UConverter::UTF32_BigEndian === $c->getSourceType()); var_dump(UConverter::SBCS === $c->getDestinationType());
<?php $c = new UConverter('ascii', 'utf-8'); foreach (array('?', '', '<unknown>') as $subst) { if (!$c->setSubstChars($subst)) { echo "**Disallowed\n"; continue; } var_dump($c->convert("This is an ascii string")); var_dump($c->convert("Snowman: (☃)")); }
<?php var_dump(UConverter::getStandardName('latin1', 'MIME')); var_dump(UConverter::getStandardName('latin1', 'IANA')); var_dump(UConverter::getStandardName('blergh', 'blergh'));
<?php var_dump(UConverter::getMIMEName('latin1')); var_dump(UConverter::getMIMEName('blergh'));
<?php foreach (array('?', '', '??') as $subst) { $opts = array('to_subst' => $subst); $ret = UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts); if ($ret === NULL) { echo "Error: ", intl_get_error_message(), "\n"; } else { var_dump($ret); } $ret = UConverter::transcode("Snowman: (☃)", 'ascii', 'utf-8', $opts); if ($ret === NULL) { echo "Error: ", intl_get_error_message(), "\n"; } else { var_dump($ret); } }
<?php $avail = UConverter::getAvailable(); var_dump(count($avail) > 100); var_dump(in_array('UTF-7', $avail)); var_dump(in_array('CESU-8', $avail)); var_dump(in_array('ISO-8859-1', $avail)); $latin1 = UConverter::getAliases('latin1'); var_dump(in_array('ISO-8859-1', $latin1));
<?php $standards = UConverter::getStandards(); var_dump(in_array('IANA', $standards)); var_dump(in_array('MIME', $standards));
<?php $o = new UConverter(1, 1); $o->toUCallback(1, 1, 1, $b); var_dump($o->getErrorCode());