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

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

问题描述

我正在编写一个从数据库源中提取的PHP程序。一些varchars有引号,显示为黑色钻石,带有问号( ,替换字符,我从Microsoft Word文本中假设)。



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

解决方案

如果您看到该字符( U + FFFDREPLACEMENT CHARACTER),通常意味着文本本身以某种形式的单字节编码,但在unicode编码之一(UTF8或UTF16)中解释。



如果是另一种方式,它通常会看起来像这样:ä。



原始编码可能是ISO-8859-1,也称为Latin-1。您可以检查这一点,而无需更改您的脚本:浏览器可让您选择以不同的编码重新解释页面 - 在Firefox中使用查看 - >字符编码。要使浏览器使用正确的编码,请添加如下HTTP头:


$ b

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

或将编码放在元标记中:

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

或者,您可以尝试以另一种编码(UTF-8,最好是)或从数据库读取数据 iconv() 的文字。


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).

How can I use php to strip these characters out?

解决方案

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: ä.

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".

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">

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天全站免登陆