Why does someone want to use strlen instead of mb_strlen

There is some old code that I have to convert from iso-8859-2 to UTF-8 . One problem is the widespread use of the strlen function. At first I thought that I replaced all occurrences of strlen with mb_strlen .

However, my colleague said that this would be a mistake. I know the difference between the two functions - in the case of accented characters in a string, strlen returns the number of bytes that it actually takes, and mb_strlen returns the number of characters.

And now, a colleague said that maybe there is somewhere a situation where the return should be about the number of bytes in the string, but he could not give me any examples of such a situation.

There are about 900 of strlen whole code, and it will take several days to analyze each individual event.

Question: what are the potential situations when someone needs the number of bytes instead of the number of characters in a string?

+4
source share
1 answer

Several situations come to mind:

  • Saving a string in a file or database
  • Write string to socket to send over network
  • Calling an obsolete API or COM method that requires a length in bytes
+6
source

All Articles