• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP function chunk_split() – Split a string into smaller chunks

by admin

The chunk_split() function divides a string into a sequence of small fragments. chunk_split() adds the character(s) specified in chunk_ending every chunk_length characters. This function is useful for breaking certain types of data into separate lines of a specified length. It’s often used to make base64 encoded data conform to RFC 2045. This function was introduced in PHP3.

Syntax:

string chunk_split(string string, [int chunk_length], [string chunk_ending])

Parameters

Parameter Description
string String to split into chunks
chunk_length Length of the chunks (default 76)
chunk_ending Character(s) to place at the end of each chunk (default \r\n)

Return Values

String with chunk_ending placed every chunk_length

Examples

Example 1:

<?php
// formatting $info by using the RFC 2045 semantics
$new_strng = chunk_split(base64_encode($info)); ?>

Example 2:

$data = "...some long data...";
$converted = chunk_split(base64_encode($data));
Note: This function should not be used for breaking long lines of text into shorter lines for display purposes—use wordwrap() instead.

Filed Under: PHP

Some more articles you might also be interested in …

  1. PHP bindec function – Convert a number between arbitrary bases
  2. PHP function str_repeat() – Repeat a string
  3. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another
  4. PHP Function str_split() – Convert a string to an array
  5. PHP function stripslashes() – Un-quotes a quoted string
  6. PHP connection_status function – Returns connection status bitfield
  7. PHP asin function – Arc sine
  8. PHP function acos – Arc cosine
  9. PHP Function strncasecmp() – Binary safe case-insensitive string comparison of the first n characters
  10. How to test a PHP script

You May Also Like

Primary Sidebar

Recent Posts

  • “az storage blob” Command Examples (Manage blob storage containers and objects in Azure)
  • “az storage account” Command Examples (Manage storage accounts in Azure)
  • “az sshkey” Command Examples (Manage ssh public keys with virtual machines)
  • “az redis” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright