JAGeZe Share with: Twitter Pinterest Email LinkedIn Digg StumbleUpon Print Bufferapp LinkedIn LinkedIn LinkedIn LinkedIn WhatsApp About Found this useful? Please consider donating, Thank You! Donate
Home (JAGeZe)

Tuesday, September 8, 2020

Beware Using UTF8-BOM Encoding in PHP Code

Beware Using UTF8-BOM Encoding in PHP Code

Some months ago I wrote a PHP program to send out a mailshot from  a list of email addresses and names...

Somehow my source code on my PC became corrupted so I copied it all from my server using Windows Notepad.

This program would produce a PowerShell script from the data provided, then download it. When testing, the download just didn't work - message "Warning: cannot modify header information - headers already sent by..."! Try as I might, I just kept getting this error... This comes from using the PHP command header() after something has been sent for display! I went through my code line by line and just could not see where this was occurring. After much trawling I came across a suggestion on stackoverflow.com - UTF8-BOM encoding can cause blank lines to be displayed...

So, I looked at my code and yes, the encoding was UTF8-BOM (apparently Windows Notepad does this!). I converted the source using Notepad++ to just UTF8 and lo and behold, all worked as it should work!

A big "Thank You" to stackoverflow.com for the tips - useful in lots of cases I might add but you do have to sort through some of the BS posted by a small number of idiots...


No comments:

Post a Comment