Jump to content

Difference in the split functions?


silkfire

Recommended Posts

They are similar, but have different outputs and default split lengths.

 

str_split() returns an array and defaults to a split being made every character.

 

chunk_split() returns a string with \r\n placed every 76 characters.

 

For both functions, the split length can be changed with an optional 2nd parameter.

 

In essence, str_split is useful for exploding strings based on a chunk length as opposed to a needle with explode().  chunk_split() is primarily useful for formatting certain long strings to meet RFC semantics.  This is mostly for hash values and encryption methods that potentially produce strings longer than 76 characters.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.