Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: is the implode() function safe for multibyte strings?

The explode() function has a correlating multibyte-safe function in mb_split().

I don't see a correlating function for implode(). Does this imply that implode is already safe for multibyte strings?

like image 743
David Jones Avatar asked Dec 19 '11 17:12

David Jones


People also ask

What would implode explode string )) do?

As the name suggests Implode/implode() method joins array elements with a string segment that works as a glue and similarly Explode/explode() method does the exact opposite i.e. given a string and a delimiter it creates an array of strings separating with the help of the delimiter.

Is Str_replace multibyte safe?

The code is perfectly safe with sane multibyte-encodings like UTF-8 and EUC-TW, but dangerous with broken ones like Shift_JIS, GB*, etc. Rather than going through all the headache and overhead to be safe with these legacy encodings, I would recommend just supporting only UTF-8.

What is the implode function in PHP?

Definition and Usage The implode() function returns a string from the elements of an array. Note: The implode() function accept its parameters in either order. However, for consistency with explode(), you should use the documented order of arguments. Note: The separator parameter of implode() is optional.

What is multibyte string?

A multibyte character is a character composed of sequences of one or more bytes. Each byte sequence represents a single character in the extended character set. Multibyte characters are used in character sets such as Kanji. Wide characters are multilingual character codes that are always 16 bits wide.


1 Answers

As long as your delimiter and the strings in the array contain only well-formed multibyte sequences there should not be any issues.

implode basically is a fancy concatenation operator and I couldn't imagine a scenario where concatenation is not multibyte safe ;)

like image 134
NikiC Avatar answered Nov 02 '22 06:11

NikiC