本文整理汇总了PHP中iconv函数的典型用法代码示例。如果您正苦于以下问题:PHP iconv函数的具体用法?PHP iconv怎么用?PHP iconv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iconv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reParceCategoriesAction
/**
* @todo перенести в комманды
* Контроллер для записи Категорий
* @Secure(roles = "ROLE_ADMIN")
* @Route("/testxmlcat", name = "testcategories")
*/
public function reParceCategoriesAction()
{
$html = file_get_contents("http://www.medknigaservis.ru/ervr/medknigaservis.xml");
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
$html = iconv("windows-1251", "utf-8", $html);
$saw = new \nokogiri($html);
$xml = $saw->get('category')->toArray();
#echo '<pre>';
#print_r($xml);
#echo '</pre>';
#echo '<hr />';
for ($i = 0; true; $i++) {
if (isset($xml[$i]['#text'][0])) {
echo '<b>' . $xml[$i]['#text'][0] . '</b><br />';
$cat = new MarketCategory();
$cat->setName($xml[$i]['#text'][0]);
$cat->setOfferId($xml[$i]['id']);
$em = $this->getDoctrine()->getManager();
$em->persist($cat);
$em->flush();
} else {
break;
}
}
return $this->render('EvrikaMainBundle:Shop:main.html.twig');
}
示例2: addm
function addm($char, $mes, $priv)
{
setlocale(LC_ALL, "ru_RU.CP1251");
if (!isset($char['sex']) || $char['sex'] == "male") {
$mes = preg_replace("/\\{([\\d\\w\\s]*?)\\|([\\d\\w\\s]*?)\\}/i", "\\1", $mes);
} else {
$mes = preg_replace("/\\{([\\d\\w\\s]*?)\\|([\\d\\w\\s]*?)\\}/i", "\\2", $mes);
}
$mes = '<span style="color:#FF2828;font-size:12px;">' . iconv("Windows-1251", "UTF-8//IGNORE", $mes) . '</style>';
$message = $mes;
$message = mysql_real_escape_string($message);
$sel = myquery("SELECT `count` FROM `game_bot_chat_resp` WHERE `id` = '" . $char['name'] . "';");
$n = mysql_fetch_array($sel);
if ($n['count'] <= 4) {
myquery("INSERT INTO `game_bot_chat_resp` (`id`,`count`) VALUES ('" . $char['name'] . "','1') ON DUPLICATE KEY UPDATE `count` = `count` + 1;");
$update_chat = myquery("insert into game_log (town,fromm,too,message,date,ptype) values (0,'-1','" . $char['user_id'] . "','" . $message . "','" . time() . "'," . $priv . ")");
} else {
$sel = myquery("SELECT `text` FROM `game_bot_chat_annoy` ORDER BY RAND() ASC LIMIT 1");
$mes = mysql_fetch_array($sel);
if (!isset($char['sex']) || $char['sex'] == "male") {
$mes = preg_replace("/\\{([\\d\\w\\s]*?)\\|([\\d\\w\\s]*?)\\}/i", "\\1", $mes);
} else {
$mes = preg_replace("/\\{([\\d\\w\\s]*?)\\|([\\d\\w\\s]*?)\\}/i", "\\2", $mes);
}
$message = mysql_real_escape_string('<span style="color:#FF2828;font-size:12px;">' . iconv("Windows-1251", "UTF-8//IGNORE", $mes['text']) . '</style>');
$update_chat = myquery("insert into game_log (town,fromm,too,message,date,ptype) values (0,'-1','" . $char['user_id'] . "','" . $message . "','" . time() . "'," . $priv . ")");
}
}
示例3: profileDefault
private function profileDefault($mode = 'run', $priceType = null)
{
if ($mode == 'info') {
return ['name' => 'Базовый', 'description' => 'Профиль по умолчанию'];
}
if ($mode == 'run') {
$offers = \app\models\Offers::find()->all();
$arCsv = ['Название;Поставщик;Исходная цена;Посчитанная цена;Количество'];
$providers = \app\models\Providers::find()->all();
$arProviders = [];
foreach ($providers as $value) {
$arProviders[$value->id] = $value->name;
}
foreach ($offers as $offer) {
$name = \app\components\Goods::getName($offer->goods_id);
$provider = $arProviders[$offer->providers_id];
$price = $offer->price;
$quantity = $offer->quantity;
// print $name;
$calcPrice = $price * \app\components\CalculationDiscount::calc($offer->goods_id, $offer->providers_id, $priceType);
// $calcPrice = \app\components\CalculationDiscount::calc($offer);
$arCsv[] = "{$name};{$provider};{$price};{$calcPrice};{$quantity}";
}
$csv = implode(chr(10), $arCsv);
$this->_unloadStr('prise.csv', iconv('utf-8', 'windows-1251', $csv));
}
}
示例4: sanitize
public static function sanitize($text)
{
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
$text = trim($text, '-');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
return preg_replace('~[^-\w]+~', '', $text);
}
示例5: setCode
/**
* @brief 编码转换
* @param string &$str 被转换编码的字符串
* @param string $outCode 输出的编码
* @return string 被编码后的字符串
*/
public static function setCode($str, $outCode = 'UTF-8')
{
if (self::isUTF8($str) == false) {
return iconv('GBK', $outCode, $str);
}
return $str;
}
示例6: buildXml
/**
* handle request and build XML
* @access protected
*
*/
protected function buildXml()
{
if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
}
if (!isset($_GET["FileName"])) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
}
$fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]);
$_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $_resourceTypeInfo->checkIsHiddenFile($fileName)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
if (!$_resourceTypeInfo->checkExtension($fileName, false)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
$filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName);
$bDeleted = false;
if (!file_exists($filePath)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND);
}
if (!@unlink($filePath)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
} else {
$bDeleted = true;
}
if ($bDeleted) {
$thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName);
@unlink($thumbPath);
$oDeleteFileNode = new Ckfinder_Connector_Utils_XmlNode("DeletedFile");
$this->_connectorNode->addChild($oDeleteFileNode);
$oDeleteFileNode->addAttribute("name", iconv('gbk', 'utf-8', $fileName));
//$oDeleteFileNode->addAttribute("name", $fileName);
}
}
示例7: HandleAddItem
function HandleAddItem()
{
define("CMD_ADD_OURITEM", <<<SQL
\t\tINSERT INTO our_items (name, our_category_id, art, mdate)
\t\t\tVALUES (?, ?, ?, NOW())
SQL
);
define("CMD_SEL_OURITEM_NEWID", <<<SQL
\t\tSELECT id FROM our_items
\t\t\tWHERE name = ? AND our_category_id = ? AND art = ?
SQL
);
global $db;
$newItem = iconv("UTF-8", "windows-1251", urldecode($_REQUEST["itemName"]));
$art = "art" . $_REQUEST["parentNodeId"] . "_" . time();
$res =& $db->query(CMD_ADD_OURITEM, array($newItem, $_REQUEST["parentNodeId"], $art));
if (PEAR::isError($res)) {
printError($res);
exit;
}
$newId =& $db->getOne(CMD_SEL_OURITEM_NEWID, array($newItem, $_REQUEST["parentNodeId"], $art));
if (PEAR::isError($newId)) {
printError($newId);
exit;
}
// ¬озвратить номер добавленой категории
print trim($newId);
}
示例8: testLoadDOMDocumentUTF16
/**
* @depends testLoadDOMDocument
*/
function testLoadDOMDocumentUTF16()
{
$xml = '<?xml version="1.0" encoding="UTF-16"?><root xmlns="DAV:">blabla</root>';
$xml = iconv('UTF-8', 'UTF-16LE', $xml);
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
$this->assertEquals('blabla', $dom->firstChild->nodeValue);
}
示例9: translate
public static function translate($string)
{
$pinyin_table = self::$pinyin_table;
$flow = array();
$string = iconv('UTF-8', 'GB2312', $string);
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
$h = ord($string[$i]);
if ($h >= 0x81 and $h <= 0xfe) {
if (isset($string[$i + 1])) {
$i++;
$l = ord($string[$i]);
if (isset($pinyin_table[$h][$l])) {
array_push($flow, $pinyin_table[$h][$l]);
} else {
array_push($flow, $h);
array_push($flow, $l);
}
} else {
array_push($flow, ord($string[$i]));
}
} else {
array_push($flow, ord($string[$i]));
}
}
$pinyin = array();
$size = sizeof($flow);
for ($i = 0; $i < $size; $i++) {
if (is_array($flow[$i])) {
array_push($pinyin, $flow[$i][0]);
}
}
return $pinyin;
}
示例10: utf_conv
function utf_conv($iso, $charset, $what)
{
if (function_exists('iconv')) {
$what = iconv($iso, $charset, $what);
}
return $what;
}
示例11: prepare
public static function prepare()
{
if ($_SERVER['CONTENT_TYPE'] && preg_match('/charset=([^;]*)/', $_SERVER['CONTENT_TYPE'], $matches)) {
$encoding = strtoupper($matches[1]);
} else {
$encoding = ENCODING;
}
$urlencoded = strpos($_SERVER['CONTENT_TYPE'], 'urlencoded');
foreach ($_REQUEST as $var => $val) {
$value = $val;
if ($urlencoded) {
if (!is_array($value)) {
$value = urldecode($value);
} else {
foreach ($value as $i => $v) {
$value[$i] = urldecode($v);
}
}
}
if ($encoding and $encoding != ENCODING) {
$value = iconv($encoding, ENCODING, $value);
}
$_REQUEST[$var] = $value;
}
}
示例12: do_iCMS
public function do_iCMS($a = null)
{
if ($_GET['name']) {
$name = $_GET['name'];
$encode = mb_detect_encoding($name, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
if (strtoupper($encode) != 'UTF-8') {
if (function_exists('iconv')) {
$name = iconv($encode, 'UTF-8//IGNORE', $name);
} elseif (function_exists('mb_convert_encoding')) {
$name = mb_convert_encoding($name, 'UTF-8//IGNORE', $encode);
}
}
$val = iS::escapeStr($name);
$field = 'name';
} elseif ($_GET['tkey']) {
$field = 'tkey';
$val = iS::escapeStr($_GET['tkey']);
} elseif ($_GET['id']) {
$field = 'id';
$val = (int) $_GET['id'];
} else {
iPHP::throw404('标签请求出错', 30001);
}
return $this->tag($val, $field);
}
示例13: PackMsg
public function PackMsg($arr)
{
$bind = unserialize($arr['MessegeContent']);
$packstr = $bind['PackFormat'];
$res = pack($packstr, $bind['Length'], $bind['Length2'], $bind['uType'], $bind['MsgLevel'], $bind['Line'], $bind['CountDown'], iconv("utf-8", "GB2312", $bind['MessegeContent'] . ""));
return $res;
}
示例14: PMA_aix_iconv_wrapper
/**
* Wrapper around IBM AIX iconv(), whose character set naming differs
* from the GNU version of iconv().
*
* @param string input character set
* @param string output character set
* @param string the string to convert
*
* @return mixed converted string or FALSE on failure
*
* @access public
*
* @author bwiberg Björn Wiberg <Bjorn.Wiberg@its.uu.se>
*/
function PMA_aix_iconv_wrapper($in_charset, $out_charset, $str)
{
global $gnu_iconv_to_aix_iconv_codepage_map;
// Check for transliteration argument at the end of output character set name
$translit_search = strpos(strtolower($out_charset), '//translit');
$using_translit = !($translit_search === FALSE);
// Extract "plain" output character set name (without any transliteration argument)
$out_charset_plain = $using_translit ? substr($out_charset, 0, $translit_search) : $out_charset;
// Transform name of input character set (if found)
if (array_key_exists(strtolower($in_charset), $gnu_iconv_to_aix_iconv_codepage_map)) {
$in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)];
}
// Transform name of "plain" output character set (if found)
if (array_key_exists(strtolower($out_charset_plain), $gnu_iconv_to_aix_iconv_codepage_map)) {
$out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($out_charset_plain)];
}
// Add transliteration argument again (exactly as specified by user) if used
// Build the output character set name that we will use
$out_charset = $using_translit ? $out_charset_plain . substr($out_charset, $translit_search) : $out_charset_plain;
// NOTE: Transliteration not supported; we will use the "plain" output character set name
$out_charset = $out_charset_plain;
// Call iconv() with the possibly modified parameters
$result = iconv($in_charset, $out_charset, $str);
return $result;
}
示例15: checkFileContent
protected static function checkFileContent()
{
$fileContent = file_get_contents(static::$tmpFilepath);
// check encoding and convert to utf-8 when necessary
$detectedEncoding = mb_detect_encoding($fileContent, 'UTF-8, ISO-8859-1, WINDOWS-1252', true);
if ($detectedEncoding) {
if ($detectedEncoding !== 'UTF-8') {
$fileContent = iconv($detectedEncoding, 'UTF-8', $fileContent);
}
} else {
echo 'Zeichensatz der CSV-Date stimmt nicht. Der sollte UTF-8 oder ISO-8856-1 sein.';
return false;
}
//prepare data array
$tmpData = str_getcsv($fileContent, PHP_EOL);
array_shift($tmpData);
$preparedData = [];
$data = array_map(function ($row) use(&$preparedData) {
$tmpDataArray = str_getcsv($row, ';');
$tmpKey = trim($tmpDataArray[0]);
array_shift($tmpDataArray);
$preparedData[$tmpKey] = $tmpDataArray;
}, $tmpData);
// generate json
$jsonContent = json_encode($preparedData, JSON_HEX_TAG | JSON_HEX_AMP);
self::$jsonContent = $jsonContent;
return true;
}