Page 1 of 1

cant work with ASCII extended chars in PHP

Posted: Wed Feb 24, 2010 4:03 am
by vikingro
hi,
i am kinda new to php and i need to work with ASCII II characters those with code beyond 127.

The problem is that I am trying to run this script below, and I dont get my required characters from ASCII table that had to represent the ascii codes beyond 127.

Code: Select all

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>
    </title>
    </head>
    <body>
 
    <?php
        for ($j = 128; $j<255; $j++){
            echo (chr($j)) ."&nbsp;&nbsp;";
        }
?>      
    </body>
</html>
 
I have tried without using the meta header. I have also tried to use the utf8_encode php function, but nothing has helped.
I need to manipulate in my php page ascii characters like theese.
« - 174
? - 218
? - 251
ü - 129
? - 183
? - 169
» - 175
? - 210

If anyone has an idea about how to solve this would be very appreciated.
Thank you very much.

Re: cant work with ASCII extended chars in PHP

Posted: Wed Feb 24, 2010 8:36 am
by AbraCadaver
You won't get all, but try:

Code: Select all

echo htmlentities(chr($j)) ."&nbsp;&nbsp;";
// or better
echo "&#" . $j ."&nbsp;&nbsp;"; 

Re: cant work with ASCII extended chars in PHP

Posted: Wed Feb 24, 2010 10:25 am
by Apollo
vikingro wrote:i am kinda new to php and i need to work with ASCII II characters those with code beyond 127.
There are no ASCII characters above 127.

Perhaps you mean ANSI, and in that case, which ANSI encoding? Win1252? Latin1? CP950 (Chinese) ?

Furthermore, in your example you output a UTF-8 content type in your HTML header. But the data you are outputting is not UTF-8 encoded.
You mentioned you tried utf8_encode, but that converts ISO-8859-1 Ansi to UTF-8, and that particular ansi encoding does not even contain characters 127-159.

Re: cant work with ASCII extended chars in PHP

Posted: Wed Feb 24, 2010 11:21 am
by AbraCadaver
First let me say that I know very little about character encoding, unicode, etc., but just looking here shows me the characters that are also included in the extended ASCII range: http://www.utf8-chartable.de/unicode-ut ... inhtml=hex

This works for me, though as I said, I don't have much experience with it:

Code: Select all

for ($j=hexdec('a0'); $j<=hexdec('3ff'); $j++){
    echo "&#x".dechex($j).";&nbsp;&nbsp;";
}

Re: cant work with ASCII extended chars in PHP

Posted: Wed Feb 24, 2010 4:35 pm
by MichaelSK
See ICONV

Re: cant work with ASCII extended chars in PHP

Posted: Thu Feb 25, 2010 1:14 am
by vikingro
UPDATE: I have solved. The encoding was CP437, wich btw doesnt work in php.
Anyway, I have found out that only putty was displaying in cp437 where the password was encripted with Latin1.

thanks for replies.
Perhaps you mean ANSI, and in that case, which ANSI encoding? Win1252? Latin1? CP950 (Chinese) ?
You are right. I need the ANSI encoding first used by IBM in DOS.
I have found it in Windows character map: DOS:United States.
Now the problem is if I can find it's name to use it in php header.

PS: I need to decode an Informix 4GL coded password. Anyone knows the precise name of the charset in 4GL?