7

This is a follow-on question from this one: Algorithm to dynamically merge arrays

There are unescaped characters in some of the cells in the spreadsheet. I try to escape them with addslashes() but phpexcel seems to ignore this and stop processing the rest of the rows. I get this error in the logs:

 PHP Warning:  Unexpected character in input:  '\' (ASCII=92) state=1

I've looked through the API; I haven't seen any text formatting methods that I can use. (Please correct me if I'm wrong)

Your help is appreciated.

Community
  • 1
  • 1
Mina
  • 610
  • 7
  • 21
  • 1
    addslashes doesn't escape periods, php.net tells me.... o_O. – Mina Dec 23 '11 at 07:53
  • 2
    PHPExcel doesn't care about slashes, they're just characters in a string.... the only proviso is to use UTF-8. As long as your follow PHP's own rules with strings, you shouldn't have any problems with the library, so clearly this is something else. Can you please provide an example of what strings are causing you problems, and how you're reading them from PHPExcel and storing them in the database. – Mark Baker Dec 23 '11 at 09:21

1 Answers1

2

From the PHP documenation:

"It is necessary to use UTF-8 encoding for all texts in PHPExcel. If the script uses different encoding then it is possible to convert the texts with PHP's iconv() function."

Escaping the characters won't do anything, as the characters that are not valid UTF8 characters, will stay invalid.

Although you could do character set conversion when you pass the data to PHPExcel, I'd instead strongly recommend switching your whole project to UTF8 as dealing with multiple character sets in one project is not a good problem to have.

Danack
  • 24,939
  • 16
  • 90
  • 122