Skip to content

Enable handling of unicode characters #1

Description

@bewedeg

Hi Tony,
I think i might have found a small issue in

$fieldConfig, substr($line, $i, $fieldConfig['size'])

In Germany and other countries there are special characters like ä, ö, ü, ß and so on. If the underlying file has these encoded in unicode substr in PHP does not handle these characters very nicely, as the character bytewise is cut in half leaving garbage. PHP has mb_substr(...) to handle this character in the correct manner.

I replaced that in a local copy and i can confirm that it works as expected.
$fieldConfig, mb_substr($line, $i, $fieldConfig['size'])

Regards,
Bernhard

Activity

  1. tonyfarney commented on May 31, 2022

    @tonyfarney
    Owner

    You are right! The library lacks in providing support for that kind of situation. I am not used with those characters, but it appears to be an encoding issue. In the case you pointed out, my understanding is that a symbol that is considered to be 1 character is actually encoded as 2 characters. Is that the case? If so, I think that the correct approach is to use an encoding that properly represents that simbols as 1 character.

  2. bewedeg commented on May 31, 2022

    @bewedeg
    Author

    I just looked at the file and its plain ANSI
    image
    Ü is stored as HEX dc

    which leaves me even more puzzled why substr doesn't handle this case correct but mb_substr does.

  3. tonyfarney commented on Jun 2, 2022

    @tonyfarney
    Owner

    Interesting. If just replacing by mb_substr solved the issue, please feel free to issue a PR. But it's necessary to check if the function exists (as it is part of the mbstring extension) before using it. If it's not defined, fallback to substr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions