PHP: str_split() function
The str_split() function is used to convert a string to an array.
(PHP 5 )
|string_name||The string to be split.||Required||String|
|split_length||The length of the chunk.||Optional||Integer|
If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise, each chunk will be one character in length.
FALSE is returned if split_length is less than 1.
If the split_length length exceeds the length of the string, the entire string is returned as the first (and only) array element.
Value Type: Array.
<?php $string_name='Welcome to w3resource.com'; print_r(str_split($string_name)); echo '<br>'; print_r(str_split($string_name,4)); echo '<br>'; ?>
Array (  => W  => e  => l  => c  => o  => m  => e  =>  => t  => o  =>  => w  => 3  => r  => e  => s  => o  => u  => r  => c  => e  => .  => c  => o  => m ) Array (  => Welc  => ome  => to w  => 3res  => ourc  => e.co  => m )
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