fgetcsv is not splition data properly

﹥>﹥吖頭↗ 提交于 2020-01-25 02:45:08

问题


i am importing csv file to upload data into database. But in some products the description is not going through properly. the description is like

TSD/UHC Model UG-132, 6\" gas revolver with plastic shells. Shells: MUG131 & MUG131BRASS. 290-320 FPS with .20g BBS.

Legal Disclaimer

Restrictions: You must be 18 or older to order this product. In some areas, state and local laws further restrict or prohibit the sale and possession of this product. In ordering this product, you certify that you are at least 18 years old and satisfy your jurisdiction\'s legal requirements to purchase this product.

Warning: This product may be mistaken for a firearm by law enforcement officers or others, and altering its color or brandishing the product in public may be considered a crime.

but when i print fgetcsv array it display this description in different array like.

[2] => TSD/UHC Model UG-132, 6\" gas revolver with plastic shells. Shells: MUG131 & MUG131BRASS. 290-320 FPS with .20g BBS. Legal Disclaimer

Restrictions: You must be 18 or older to order this product. In some areas [3] => state and local laws further restrict or prohibit the sale and possession of this product. In ordering this product [4] => you certify that you are at least 18 years old and satisfy your jurisdiction\'s legal requirements to purchase this product.
Warning: This product may be mistaken for a firearm by law enforcement officers or others [5] => and altering its color or brandishing the product in public may be considered a crime.

"

I also have more products with this kind of description with backslash, single quot and double quot. some other products are uploaded properly but some are having problem.

Thanks


回答1:


fgetcsv($handle, 0, ",", '"', '""');




回答2:


Try

fgetcsv($handle, 0, ",", '"', '\\');

which use a comma (,) as a separator, unless it's part of a field wrapped in "; and if " appears as a character in the field it must be escaped with a \

If a comma isn't the separator, then you'll need to use the appropriate separator character



来源:https://stackoverflow.com/questions/17697904/fgetcsv-is-not-splition-data-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!