AppDividend
Latest Code Tutorials

PHP chunk_split() Function Example Tutorial

0

PHP chunk_split() Function Example Tutorial is today’s topic. The chunk_split() function splits the string into a series of smaller parts. It does not return the original string. So, it is not a pure function. The chunk_split() function is the built-in function in PHP. The function is used to split the string into smaller chunks of the specific length.

PHP chunk_split() Function

PHP chunk_split() function is used to split or divide the string into chunks or small parts. It returns the split string.

The syntax of the function is following.

string chunk_split($string, $length, $end)
  1. The $string parameter specifies a string which is needed to be chunked.
  2. The $length parameter specifies an integer which defines the chunk length. That is the length of the chunked parts.
  3. The $end parameter specifies the line ending sequence.

See the code example.

<?php

$str = "BobbyBrown";
echo chunk_split($str, 5, "...");

See the output.

➜  pro php app.php
Bobby...Brown...                                                                
➜  pro

See another example of Friends.

<?php

$centralperk = "FRIENDS";
echo chunk_split($centralperk, 1, ".");

See the output.

➜  pro php app.php
F.R.I.E.N.D.S.                                                                  
➜  pro

Remember, The chunk_split() function doesn’t return an array, but rather a string.

If you want to use it, you would have to convert the string returned by the chunk_split() function into an array.

The result of chunk_split() in PHP 5.0.4 does not match the result in other versions of PHP.

Finally, PHP chunk_split() Function Example Tutorial is over.

Recommended Posts

  1. PHP count_chars() Function Example Tutorial
  2. PHP Strlen Example | strlen() Function Tutorial
  3. PHP strtotime Example | PHP strtotime() Function Tutorial
  4. PHP strpos() Example | PHP strpos() Function Tutorial
  5. PHP Trim Example | trim() Function In PHP Tutorial

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.