0

In my php code

'user' => !empty($_POST['user']) ? substr($_POST['user'],0,10) : '',

In my template

<input type="text" maxlength="10" value='$context['user']'/>

With this I get the input to admit a maximum of 10 characters, and if someone cheats, and removes the maxlength, the php code will continue taking only 10 characters. In cases such as special characters, it counts as 2 characters, that is, if I put "ññññññññññ" in the database, it will only save "ñññññ" because that character counts as 2.

How could I make the php function (substr) count the special characters as 1 character and not as 2, or input count good special characters?

Estudiante
  • 107
  • 2

1 Answers1

0

Use mb_substr instead of substr, it will take into account multibyte characters.

There are several php functions prefixed by mb_ which have been added to handle multibyte characters. Please not that by nature these functions will be a bit slower because they walk through every character to perform their task, so when you are perfectly sure that there is no multibyte character, you may prefer to use the "basic" version like substr.

yolenoyer
  • 8,797
  • 2
  • 27
  • 61