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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.