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 函数
  • 相关阅读:
    css文档之盒模型阅读笔记
    《图解HTTP》阅读总结
    好博客-持续收藏中。。。
    Linux下Nagios的安装与配置
    在Linux上使用logwatch分析监控日志文件
    根据Request检测是否为移动端设备访问
    MyEclipse启动一直停留在Loading workbench界面上的处理
    使用JSONP进行跨域请求
    Page.java
    JsonUtil.java
  • 原文地址:https://www.cnblogs.com/you-jia/p/4123710.html
Copyright © 2011-2022 走看看