Unicode string php

前端 未结 3 1933
盖世英雄少女心
盖世英雄少女心 2021-01-22 19:14

I have a question! I want to print an unicode string in php (like \'سلام\')! but when I use echo only some ??? apear!!!

what whould I do??? This happens hen I want to c

3条回答
  •  野性不改
    2021-01-22 19:57

    You need to do three things:

    1. Make sure you're receiving the data as UTF-8 data. For MySQL, query SET NAMES 'utf8' before selecting records.
    2. Make sure you're using UTF-8 compatible functions when dealing with UTF-8 strings.
    3. Make sure you're setting the output encoding as UTF-8. For HTML, this can be done by setting the Content-type HTTP header to (e.g.) text/html; charset=utf-8.

    Of course, replace "UTF-8" with whatever encoding you want which supports the characters you need. There's no need to change the database tables (except for possible performance gains). You may need to change HTML templates, etc. if you decide on UTF-16 or something else which isn't (mostly) ASCII-compatible.

提交回复
热议问题