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 函数
  • 相关阅读:
    Kotlin扩展深入解析及注意事项和可见性
    Kotlin属性揭秘与延迟初始化特性
    Kotlin伴生对象及其字节码内幕详解
    Kotlin继承与重写重要特性剖析
    Kotlin构造方法详解与初始化过程分析
    Range与面向对象的Kotlin
    Kotlin编译器优化与when关键字详解
    Kotlin基础特性深入讲解
    java读取mysql表的注释及字段注释
    mysql导入导出sql文件
  • 原文地址:https://www.cnblogs.com/you-jia/p/4123710.html
Copyright © 2011-2022 走看看