how to get rid of an bom error in a json/php file

Viewed 67

I spent a couple of hours to find this really simple error. I hope this little tutorial helps some else to solve this problem faster.

It had an invalid json file, which I created with my php code: enter image description here

At the end of the file was a invisible character - a byte order mark (BOM). I converted my file to "UTF without BOM":

enter image description here

I replaced all BOMs:

preg_replace('/^\xef\xbb\xbf/', '', $string);

but nothing helped. Then I changed the view to hex (UltraEdit German: STRG + H, Ultraedit English: CTRL + H):

enter image description here

Solution:

To make a long story short: I just deleted the last character ">" and the BOM was gone:

enter image description here

Really stupid to waste some hours for such a simple solution. Maybe this helps someone else.

0 Answers
Related