zoukankan      html  css  js  c++  java
  • iconv

    string iconv ( string in_charset, string out_charset, string str ) 
    注意:第二个参数,除了可以指定要转化到的编码以外,还可以增加两个后缀://TRANSLIT 和 //IGNORE,其中 //TRANSLIT 会自动将不能直接转化的字符变成一个或多个近似的字符,//IGNORE 会忽略掉不能转化的字符,而默认效果是从第一个非法字符截断。 

    手册解释如下:

    in_charset

    The input charset.

    out_charset

    The output charset.

    If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character and anE_NOTICE is generated.

     

    例子

    <?php
    $text = "This is the Euro symbol '€'.";

    echo 'Original : ', $text, PHP_EOL;
    echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
    echo 'IGNORE   : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
    echo 'Plain    : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;

    ?>

    The above example will output something similar to:

    Original : This is the Euro symbol '€'.
    TRANSLIT : This is the Euro symbol 'EUR'.
    IGNORE   : This is the Euro symbol ''.
    Plain    :
    Notice: iconv(): Detected an illegal character in input string in .iconv-example.php on line 7
    This is the Euro symbol '

    如果仍有错误,可以试试mb_convert_encoding 函数
  • 相关阅读:
    读写分离
    使用xtrabackup对不同版本的mysql进行备份还原
    tomcat开启管理页面
    面试简单整理之rabbitmq
    面试简单整理之zookeeper
    面试简单整理之mybatis
    面试简单整理之spring、spring mvc
    面试简单整理之Redis
    记一次菜鸟的惊心动魄(另求原因和说明)
    面试简单整理之IO
  • 原文地址:https://www.cnblogs.com/you-jia/p/4123710.html
Copyright © 2011-2022 走看看