PHP输出显示小黑色钻石带有问号 [英] PHP output showing little black diamonds with a question mark

查看:965
本文介绍了PHP输出显示小黑色钻石带有问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个从数据库源拉取的php程序。一些varchars的引号显示为带有问号的黑色菱形( ,

I'm writing a php program that pulls from a database source. Some of the varchars have quotes that are displaying as black diamonds with a question mark in them (�, REPLACEMENT CHARACTER, I assume from Microsoft Word text).

如何使用php来删除这些字符?

How can I use php to strip these characters out?

推荐答案

如果你看到这个字符( U + FFFDREPLACEMENT CHARACTER),它通常意味着文本本身以某种形式字节编码,但是在unicode编码(UTF8或UTF16)之一中进行解释。

If you see that character (� U+FFFD "REPLACEMENT CHARACTER") it usually means that the text itself is encoded in some form of single byte encoding but interpreted in one of the unicode encodings (UTF8 or UTF16).

如果是其他方式,它通常会看起来像这样: 。

If it were the other way around it would (usually) look something like this: ä.

原始编码可能是ISO-8859-1,也称为Latin-1。你可以检查这个而不必改变你的脚本:浏览器给你选择重新解释一个不同的编码页面 - 在Firefox中使用视图 - >字符编码。

Probably the original encoding is ISO-8859-1, also known as Latin-1. You can check this without having to change your script: Browsers give you the option to re-interpret a page in a different encoding -- in Firefox use "View" -> "Character Encoding".

要使浏览器使用正确的编码,请添加如下的HTTP标头:

To make the browser use the correct encoding, add an HTTP header like this:

header("Content-Type: text/html; charset=ISO-8859-1");

或将编码放在元标记中:

or put the encoding in a meta tag:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

或者,您可以尝试以另一种编码(优选UTF-8)包含 iconv()

Alternatively you could try to read from the database in another encoding (UTF-8, preferably) or convert the text with iconv().

这篇关于PHP输出显示小黑色钻石带有问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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