Unicode字符串php [英] Unicode string php

查看:58
本文介绍了Unicode字符串php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题!
我想在php中打印unicode字符串(如‘سلام’)!
,但是当我使用echo时,只显示一些??? apear !!!

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 cho string that retrieved from database!

echo 'سلام';

结果是:

????

我尝试使用标头函数,但这没有帮助!

I tried using header function but that didn't help me!

推荐答案

您需要做三件事:


  1. 请确保您重新接收数据作为UTF-8数据。对于MySQL,在选择记录前先查询 SET NAMES'utf8'

  2. 请确保在处理时使用的是UTF-8兼容函数

  3. 请确保将输出编码设置为UTF-8。对于HTML,这可以通过将 Content-type HTTP标头设置为(例如) text / html来完成。 charset = utf-8

  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.

当然,将 UTF-8替换为所需的编码支持您需要的字符。无需更改数据库表(可能会提高性能)。如果您决定使用UTF-16或其他(大多)不兼容ASCII的内容,则可能需要更改HTML模板等。

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.

这篇关于Unicode字符串php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆