問題描述
我正在編寫一個從數(shù)據(jù)庫源中提取的 php 程序.一些 varchars 的引號顯示為帶有問號的黑色菱形 ( , 替換字符,我假設來自 Microsoft Word 文本).
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+FFFD "REPLACEMENT CHARACTER") 這通常意味著文本本身以某種形式的單字節(jié)編碼進行編碼但被解釋使用其中一種 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".
要使瀏覽器使用正確的編碼,請?zhí)砑舆@樣的 HTTP 標頭:
To make the browser use the correct encoding, add an HTTP header like this:
header("Content-Type: text/html; charset=ISO-8859-1");
或?qū)⒕幋a放入元標記中:
or put the encoding in a meta tag:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
或者,您可以嘗試以另一種編碼(最好是 UTF-8)從數(shù)據(jù)庫中讀取或使用 iconv()
.
Alternatively you could try to read from the database in another encoding (UTF-8, preferably) or convert the text with iconv()
.
這篇關于PHP 輸出顯示帶有問號的黑色小菱形的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!