PHP code conversion minus SIGN (connector) cannot convert issue

Source: Internet
Author: User
Tags posix translit

PHP code conversion minus SIGN (connector) cannot convert problem technology

Maybe yes posted on 2015-01-23 16:03

Using PHP's Iconv or mb_convert_encoding functions for encoding conversions, such as converting gb2312 to utf-8 encoding, does not work when certain special characters (minus, connector) appear, and may become a question mark "?". or "C". Try a variety of methods, still can't solve this problem well. The following code, after declaring the//ignore, encounters the connection symbol "-" will still become the symbol "?".

   

According to the PHP official website manual to provide the solution to try, still can't solve the problem, do not know is not my local PHP version of the problem.

Workaround One:
Please note that iconv (' UTF-8 ', ' ascii//translit ', ...) doesn ' t work properly when locale category Lc_ctype are set to C or Posix. You must choose another locales otherwise all non-ascii characters would be replaced with question marks. This was at least true with GLIBC 2.5.
Example:
Translation
Note that Iconv does not work correctly when the locale category Lc_ctype category is set to C or POSIX. You must choose another language, otherwise all non-ASCLL encodings will be replaced with a question mark "?". This problem is true under GLIBC 2.5.
Examples are as follows:

!--? Phpsetlocale (lc_ctype, ' POSIX '); Echo iconv (' UTF-8 ', ' ascii//translit ', "?lu?ou?ký k?? \ n ");//? lu?ou?k? K?? SetLocale (lc_ctype, ' Cs_cz '); Echo iconv (' UTF-8 ', ' ascii//translit ', '?lu?ou?ký k?? \ n ")//Zlutoucky kun  

Workaround two:
that would strip invalid characters from UTF-8 strings (so the can insert it into a database, etc.). Instead of "None" you can also use the value if you want it to insert spaces in place of the invalid characters.

 

Read (75) reviews (0) View comments

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.