Getting unwanted characters like "_x000D_" or "x000D" in PHPExcel

Viewed 10977

I am using PHPExcel for reading and storing data from Excel, but whenever I read a row from the Excel file to insert into the database, _x000D_ or x000D is appended to the title column.

Example: when inserting, the title is 'Demo', and after reading back from the DB, it was converted to 'Demo_X00D_' or 'Demo X00D'.

1 Answers

Came across this today and I am using this to convert those escape sequences to html entities:

preg_replace('/_x([0-9a-fA-F]{4})_/', '&#x$1;', $string);

Which changes _x000D_ into 

You can take this a step further to render the actual character (which in this case is a carriage return)

html_entity_decode(preg_replace('/_x([0-9a-fA-F]{4})_/', '&#x$1;', $string));
Related