I was surprised that I was unable to find a straightforward answer to this question by searching.
I have a web application in PHP that takes user input. Due to the nature of the application, users may often use extended ASCII characters (a.k.a. "ALT codes").
My specific issue at the moment is with ALT code 26, which is a right arrow (→). This will be accompanied with other text to be stored in the same field (for example, 'this→that'
).
My column type is NVARCHAR.
Here's what I've tried:
I've tried doing no conversions and just inserting the value as normal, but the value gets stored as
thisâ??that
.I've tried converting the value to UCS-2 in PHP using
iconv('UTF-8', 'UCS-2', $value)
, but I get an error sayingUnclosed quotation mark after the character string 't'.
. The query ends up looking like this:UPDATE myTable SET myColumn = 'this�!that'
.I've tried doing the above conversion and then adding an N before the quoted value, but I get the same error message. The query looks like this:
UPDATE myTable SET myColumn = N'this�!that'
.I've tried removing the UCS-2 conversion and just adding the N before the quoted value, and the query works again, but the value is stored as
thisâ that
.I've tried using
utf8_decode($value)
in PHP, but then the arrow is just replaced with a question mark.
So can anyone answer the (seemingly simple) question of, how can I store this value in my database and then retrieve it as it was originally typed?
I'm using PHP 5.5 and MSSQL 2012. If any question of driver/OS version comes into play, it's a Linux server connecting via FreeTDS. There is no possibility of changing this.