PHP: chunk_split() function
Description
The chunk_split() function is used to split a string into a series of smaller chunks.
Version:
(PHP 4 and above)
Syntax:
chunk_split(string_name, string_length, end_string)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
string_name | The string to be split. | Required | String |
string_length | The chunk length. | Optional | Integer |
end_string | The line ending sequence. | Optional | String |
Return values
The extracted string.
Value Type: String.
Pictorial Presentation
Example:
<?php
$string_name1='w3resource.com';
echo chunk_split($string_name1,1,".");
echo '<br>';
echo chunk_split($string_name1,2,"/");
echo '<br>';
echo chunk_split($string_name1,1,"--");
?>
Output:
w.3.r.e.s.o.u.r.c.e...c.o.m. w3/re/so/ur/ce/.c/om/ w--3--r--e--s--o--u--r--c--e--.--c--o--m--
View the example in the browser
See also
Previous: chr
Next: convert_cyr_string
PHP: Tips of the Day
PHP: Remove first 4 characters of a string with PHP
You could use the substr function to return a substring starting from the 5th character:
$str = "The quick brown fox jumps over the lazy dog." $str2 = substr($str, 4); // "quick brown fox jumps over the lazy dog."
Ref : https://bit.ly/2LJDLQx
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework