I am accessing a FileMaker database from PHP via ODBC.
Whenever a text field contains unicode characters, those characters are read properly, but the LAST character of the string goes missing.
For example: "München" becomes "Münche"
Some experiments show me that for every non-ASCII character, one more character gets truncated from the end. ("Müünchen" becomes "Müünch").
Note that WRITING INTO the FileMaker DB works just fine (and all characters appear there), as does reading and writing from a MySQL DB I've used for testing. Only when reading the data out of FileMaker via ODBC does it get mangled.
I suspected the driver, but when I use odbc_result_all() the data appears fully, with all characters intact. All other functions (odbc_fetch_into(), odbc_fetch_array(), odbc_result(), etc.) return the truncated string.
I've even looked into the source at https://github.com/php/php-src/blob/master/ext/odbc/php_odbc.c but I can't quite figure out a) what does odbc_result_all() do different and b) how do I get the full string into my application?
additional details:
- PHP version: PHP 7.3.8 (cli) (built: Aug 11 2019 20:50:16) ( NTS )
- System: MacOS 10.14.6
- ODBC Driver: fmodbc.so from FileMaker, config options:
- WideAPI = Yes
- UnicodeTextTypes = Yes
- MultiByteEncoding = UTF-8
My Answer:
It seems like the issue might be related to how PHP is handling unicode characters when reading data from the FileMaker ODBC driver. One possible solution could be to try converting the string to UTF-8 encoding before using it in your PHP application.
You can try using the `iconv()` function in PHP to convert the string to UTF-8 encoding. Here's an example of how you can use `iconv()`:
php
$utf8_string = iconv("UTF-16", "UTF-8", $original_string);
You can replace `"UTF-16"` with the appropriate encoding that the FileMaker ODBC driver is using for unicode characters.
Another approach could be to try using the `mb_convert_encoding()` function in PHP to convert the string to UTF-8 encoding. Here's an example:
php
$utf8_string = mb_convert_encoding($original_string, "UTF-8", "UTF-16");
You can replace `"UTF-16"` with the appropriate encoding as needed.
By converting the string to UTF-8 encoding before using it in your PHP application, you may be able to avoid the issue of truncated strings with unicode characters.
Rate this post
5 of 5 based on 1376 votesComments