In PHP function str_split
will split into bytes, rather than characters when dealing with a multi-byte encoded string.
If you want to simulate this function in Python 3 first you have to convert strings to bytes.
def str_split(string, length):
byte_string = string.encode('utf-8')
return [byte_string[i:i+length] for i in range(0, len(byte_string), length)]
str_split("This is a test.", 8)
>>> [b'This is ', b'a test.']
str_split("これはテストです。", 8)
>>> [b'\xe3\x81\x93\xe3\x82\x8c\xe3\x81',
b'\xaf\xe3\x83\x86\xe3\x82\xb9\xe3',
b'\x83\x88\xe3\x81\xa7\xe3\x81\x99',
b'\xe3\x80\x82']