0

I'm trying to insert the sign in Excel with the Com Object from PHP

I've tried using chr(242), ó but I get only characters from ISO-8859-1 charset

I now have no idea what to use to insert the character.

Here is my function :

$string = str_replace('>=', chr(242), $string);
Marleyzs
  • 155
  • 2
  • 3
  • 12
  • 1
    What is the excel value for the ≥ sign? You might need to convert to something else. – Matt Aug 06 '12 at 14:23
  • Lazy option: Manually create an Excel file, put that character in it, read it out in PHP, get that character sequence as it appears in PHP and use that. Better option: specify the character set of the Excel file (no idea how, sure it must be possible though) and insert the correct code-point from that character set. – DaveRandom Aug 06 '12 at 14:27

1 Answers1

1

Not sure what's giving you the idea that 242 in any way resolves to "≥". chr simply gives you the byte value for that number, and "≥" is not in ISO-8859 or any other single-byte encoding I know of. For the UTF-8 encoded value, use "\xE2\x89\xA5", or simply '≥' if you encode your source code in UTF-8.

Excel notoriously sucks with encodings though, so I don't know that this will actually display correctly in Excel.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
deceze
  • 510,633
  • 85
  • 743
  • 889
  • Since my .php file is encoded in **Cp1252** when I paste '≥' it eclipse says the file must be saved in UTF-8. Won't that create bugs? Btw, `"\xE2\x89\xA5"` didn't work. Also, if i save as UTF-8, it writes `'≥'` – Marleyzs Aug 06 '12 at 14:35
  • Since CP1252 cannot encode "≥" (as I said), yes, you'll have to save it in an encoding that can encode it. I don't know whether that'll lead to bugs, that depends on your code. – deceze Aug 06 '12 at 14:37
  • `"\xE2\x89\xA5"` and `'≥'` resulted in the same result : `'≥'`. Am I doing something wrong? – Marleyzs Aug 06 '12 at 14:52
  • 1
    That means you have inserted the correct bytes (a UTF-8 encoded "≥"), but Excel is too dense to correctly understand it. I don't know what encoding Excel expects or how it can be persuaded to accept anything but CP1252 encoded text (which, again, cannot represent "≥"). – deceze Aug 06 '12 at 14:55