问题描述
我正在使用 PHPExcel 从 Excel 读取和存储数据,但是每当我从 Excel 文件中读取一行以插入到数据库中时,都会附加 _x000D_
或 x000D
到标题栏.
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.
示例:插入时,标题为'Demo',从DB读回后,转换为'Demo_X00D_'或'Demo X00D'.
Example: when inserting, the title is 'Demo', and after reading back from the DB, it was converted to 'Demo_X00D_' or 'Demo X00D'.
推荐答案
今天遇到了这个问题,我正在使用它将这些转义序列转换为 html 实体:
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);
将 _x000D_
更改为 
您可以进一步渲染实际字符(在本例中为回车)
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));
这篇关于获取不需要的字符,如“_x000D_";或“x000D"在 PHPExcel 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!