Measure string size in Bytes in php

前端 未结 5 378
感动是毒
感动是毒 2020-12-01 04:11

I am doing a real estate feed for a portal and it is telling me the max length of a string should be 20,000 bytes (20kb), but I have never run across this before.

Ho

5条回答
  •  日久生厌
    2020-12-01 04:49

    You have to figure out if the string is ascii encoded or encoded with a multi-byte format.

    In the former case, you can just use strlen.

    In the latter case you need to find the number of bytes per character.

    the strlen documentation gives an example of how to do it : http://www.php.net/manual/en/function.strlen.php#72274

提交回复
热议问题