PHP: sqlsrv problems with UTF-8 values? Set your CharacterSet option!

Are you banging your head trying to figure out how to convert a seemingly invalid UTF-8 value into a valid one? You might be surprised to know that the problem isn’t how PHP interprets the characters, but rather a database connection issue. If the UTF-8 value in question looks valid in the database but does not look right when displayed on a web page, that could mean your database connection settings are not set correctly.
Continue reading “PHP: sqlsrv problems with UTF-8 values? Set your CharacterSet option!”

PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in god_i_hate_this.php

Ever get the following error?

  • PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in…

Then you are in the same boat I was in, and unfortunately for me, the solution wasn’t as straightforward as I thought it was. The problem we are seeing is that the value being encoded to json is not UTF-8 encoded data. PHP function json_encode, unfortunately, will only accept UTF-8 as its parameter. Continue reading “PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in god_i_hate_this.php”