Splitting String
The following example is used to split a string into two parts by providing it the index that the split should occur.
<?php
function str_split_index_fn($string, $index)
{
$string = (string) $string;
$index = (int) $index;
$prefix = substr($string, 0, $index);
$suffix = substr($string, $index);
return array($prefix, $suffix);
}
$input = ‘Good Day!’;
$output= str_split_index_fn($input, 4);
print_r($output);
?>
In above example, “Good Day!” is the input which can be split into 2 parts. str_split_index_fn is user defined function, which will split the given text into 2 parts with the passed index.
