Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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'.

like image 354
Farman Khan Avatar asked Sep 19 '17 09:09

Farman Khan


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));
like image 53
Eaten by a Grue Avatar answered Oct 11 '22 15:10

Eaten by a Grue