I'm not even sure what to call this other than odd thing. I have a place in a php program where I had used a variable $csym= chr(128) to print out a Euro symbol I used the variable so I could switch between euro and $. If I have it in an included file or I set it in the program as $csym=chr(128) it prints fine, however, I moved all my configs to a mysql table which I load into an array when I start the program. Now it prints chr(128) can anyone tell me why? I am echoing $cnfig['csym'] where csym is the key in the array and the value is chr(128)

I don't get why it doesn't print the symbol now.

    How is the data stored in the MySQL table? It sounds like you literally stored the string 'chr(128)' in the MySQL table.

    Either way, why bother with chr() at all? Why not just use €?

      its stored in a varchar

      as for why not use the symbol, call me stupid but I couldn't find what the keystrokes would be. I looked it up in a character table and it didn't tell me keystrokes.

        Not sure if this is valid for any OS other than windows, but: Hold the Alt key on your keyboard, type 0128 on the number pad (e.g. not the row of numbers above the letter keys), and then release the Alt button.

        The result should be the € symbol.

        EDIT:

        minifairy;10999775 wrote:

        its stored in a varchar

        What I meant was this: What is the actual value you're storing in the database? Are you literally storing the string "chr(128)" (e.g. the letters 'chr', a left parenthesis, the number 128, right parenthesis), or are you storing the € character?

        If you're storing the former and simply outputting that string when you retrieve it from the DB, then it should be obvious why you're no longer seeing the € symbol.

          bradgrafelman wrote:

          Not sure if this is valid for any OS other than windows, but: Hold the Alt key on your keyboard, type 0128 on the number pad (e.g. not the row of numbers above the letter keys), and then release the Alt button.

          As it happens, the idea that chr(128) refers to the Euro sign itself relies on the OS being Windows, since it's only in the Windows-1251 encoding where that mapping exists (some proprietary OS mappings have it at 164 or 136 and use 128 for the generic ¤ currency symbol; Unicode has it at position U+20AC; and Latin-1/ISO8859-1 doesn't have it at all).

            Ok so how to make sure you end up with the euro symbol (btw I don't have a number pad I work on a laptop. now what?)

            so how could you store the value of chr(128) rather than the text when inserting it into a table?

              ok I've tried using the fn key (its supposed to give me number pad in they keys) + alt and I get Ç for 128 and ê for 136 and if I try 164 here it just re-directs me but it doesn't give me a euro symbol either.

                minifairy;10999789 wrote:

                so how could you store the value of chr(128) rather than the text when inserting it into a table?

                Well, either type the € character directly, or simply use the PHP function [man]chr/man to assign the character to a variable.

                minifairy;10999790 wrote:

                I get Ç for 128

                As I said earlier, you need to type 0128 (not 128).

                  My approach is:

                  1. use UTF-8 encoding for everything, including the editor, served pages, and text stored in the database; that way, whatever is used to represent € in one of those places will represent € in all of the others as well.

                  2. If direct keyboard access to characters is not available (either because there is no direct mapping supported by the OS, or because I just don't remember the code point) - "۞", for example - I use whatever utility the OS provides for the purpose (such as Windows XP's Character Map).

                    Ok Thanks a lot guys. Think I been programming too late at night lately. It all seems so logical and clear this morning. Thanks again.

                      Write a Reply...