peachpie icon indicating copy to clipboard operation
peachpie copied to clipboard

function strlen should be the byte count of the string

Open avriltank opened this issue 3 years ago • 1 comments

For example: strlen("张三") //should be 6,php code Encoding.Default.GetByteCount("张三")

if we edit the code of peachpie,there are many functions should be edited,such as "strpos","strrpos","fread"....

avriltank avatar Feb 13 '22 12:02 avriltank

You are right, in general, there are some incompatibilities.

We have tried to make PHP Unicode safe and to take advantage of the .NET native String (UTF-16) type.

There are some known exceptions described at https://docs.peachpie.io/php/unicode/

Wherever you need to treat the value as 8-bit string, you can cast it using (binary) operator, e.g.:

strlen( (binary)"张三" );

Currently, this is a known behavior, and basically, we are still evaluating what would be the right approach.

  • https://github.com/peachpiecompiler/peachpie/issues/930
  • https://github.com/peachpiecompiler/peachpie/issues/929
  • https://github.com/peachpiecompiler/peachpie/issues/910
  • https://github.com/peachpiecompiler/peachpie/issues/778
  • https://github.com/peachpiecompiler/peachpie/issues/565

jakubmisek avatar Jul 21 '22 15:07 jakubmisek