I have a string with “\u00a0”, and I need to replace it with “” str_replace fails

后端 未结 8 1252
南笙
南笙 2020-12-17 09:45

I need to clean a string that comes (copy/pasted) from various Microsoft Office suite applications (Excel, Access, and Word), each with its own set of encoding.

I\'m

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 10:13

    I just had the same problem. Apparently PHP's json_encode will return null for any string with a 'non-breaking space' in it.

    The Solution is to replace this with a regular space:

    str_replace(chr(160),' ');
    

    I hope this helps somebody - it took me an hour to figure out.

提交回复
热议问题