0
votes

A remote SMS service (I cannot influence) POSTs text messages to a PHP-controller (of a Symfony2 app if that matters) as Content-Type: application/x-www-form-urlencoded

PHP cannot decode special characters correctly.

a tcpdump shows (abbreviated - only showing the data in question )

User-Agent: smsd (libwww-perl/5.805)
Content-Type: application/x-www-form-urlencoded
Content-Length: 123

data=ae+%E4+ue+%FC+oe+%F6+sz+%DF

The original data was

ae ä ue ü oe ö sz ß

and the PHP $_POST holds (serialized)

;s:4:"data";s:19:"ae ###e ###### sz ##;

I suppose, it is the missing charset=UTF-8, that causes the troubles.

If anyone has an idea how to overcome this, I'd appreciate your answer. Thanx.

1
Why are you serializing it?AbraCadaver
I think he just did that to show us the raw contents.Barmar

1 Answers

0
votes

For this specific problem I now found a solution myself using iconv.

$decoded = iconv( 'ISO-8859-1', 'UTF-8', urldecode( $encoded ) );

I think the standard charset being used for urlencode/urldecode in PHP >= 5.4 is now UTF-8, although I didn't find anything in the changelogs for these functions specifically.