2016-11-05 98 views
1

我試圖打印ascii字符,但是當索引到達擴展字符時,它們會顯示問號 。 See image如何使用php打印所有ascii字符的列表?

例如,如果我這樣做echo chr(160);我得到oA==當它應該是一個á 我如何能得到沒有改變正確的值的頭字符集或文件編碼?

Im做後續:

for ($i=0; $i < 255; $i++) { 
    echo chr($i) . " - "; 
} 

我的文件進行編碼使用UTF-8。當我設置ISO-8859-1標題看起來不錯。 See image

header("content-type: text/html; charset=ISO-8859-1"); 

我試圖只打印一個字符。看看發生: 1- See the value of the variable and how to print in the browser.

2- See the value of the variable and how to print in the browser. 爲什麼變量得到那個奇怪的值。

+0

你確定你的文件編碼是UTF-8嗎? –

+0

是的,我確定。我使用的是崇高的文字,向我展示了這一點。 – juanmiguel431

+0

我看不出任何明顯的問題。但只是一點提示,你不能在輸出後定義標題。 –

回答

1

你最深的字符轉換爲UTF-8:

for ($i=0; $i < 255; $i++) { 
    echo mb_convert_encoding (chr($i), 'UTF-8', 'ISO-8859-1') . " - "; 
} 
+0

我試過了,但仍然沒有奏效。 – juanmiguel431

0

你可以試試這個辦法還,

<?php 
for ($i=0; $i < 255; $i++) { 
    //echo chr($i) . " - "; 
    echo mb_convert_encoding('&#' . intval($i) . ';', 'UTF-8', 'HTML-ENTITIES')." - "; 
} 
?> 
+0

我試過了,但仍然沒有工作。 – juanmiguel431

0

我可以使用機能的研究函數utf8_encode其翻譯的ISO-8859解決了我的疑問-1字到UTF-8。 :) 謝謝你的幫助。

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Document</title> 
</head> 
<body> 
<?php 

    for ($i=0; $i < 255; $i++) { 
     echo utf8_encode(chr($i)); 
    } 

?> 

</body> 
</html>