PHP code conversion minus sign (connector) cannot be converted

Source: Internet
Author: User
Tags translit
PHP code conversion minus signs (connectors) cannot be converted. PHP code conversion minus signs (connectors) cannot be converted.

Maybe yes, published on

Use PHP's iconv or mb_convert_encoding function for encoding conversion. for example, to convert gb2312 to UTF-8 encoding, some special characters (minus signs, connectors) may not work properly, it may become a question mark "? "Or" C ". I tried multiple methods and still cannot solve this problem well. The following code indicates that the connection symbol "-" still becomes a symbol "after the // IGNORE is declared "? ".

   

According to the solution provided by netizens in the PHP Official Manual, the problem still cannot be solved. I don't know if it is my local PHP version.

Solution 1:
Please note that iconv ('utf-8', 'ascii // Transcoder ',...) doesn't work properly when locale category LC_CTYPE is set to C or POSIX. you must choose another locale otherwise all non-ASCII characters will be replaced with question marks. it is at least true with glibc 2.5.
Example:
[Translation]
Note that iconv cannot work normally when the language environment class LC_CTYPE is set to C or POSIX. You must select another language. otherwise, all non-ASCLL codes will be replaced with question marks "? ". This problem is true under glibc 2.5.
Example:

    

Solution 2:
That will strip invalid characters from UTF-8 strings (so that you can insert it into a database, etc .). instead of "none" you can also use the value 32 if you want it to insert spaces in place of the invalid characters.

     

Read (75) comment (0) view comment

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.