Search code examples
unicodemoovwebtritium

How do I use length() for unicode characters?


When working in the Moovweb SDK, length("çãêá") is expected to return 4, but instead returns 8. How can I ensure that the length function works correctly when using Unicode characters?


Solution

  • This is a common issue with Unicode characters and the length() function using the wrong character set. To fix it you need to set the charset_determined variable to make sure the correct character set is being used before making the call to length(), like so in your tritium code:

    $charset_determined = "utf-8"
    # your call to length() here