I want to split array element's string. I have to split it at the fifth character, but if it's in the middle of the word, split it at the nearest whitespace. Like this:
// I have array like these
$array={"How are you ?","I am fine."};
//I want output like if we take length = 5.
$array1 = {"How are","you ?","I am fine."}; // array1[0] =how a should be array1[0] = how are .
Look for nearest whitespace to the fifth character. Then return the first part from 0 until that character and put it into new array. Then put the second chunk (the one until the end) into the same array.
foreach ($array as $val) {
$strpos = strpos($val, " ", 5);
$array1[] = substr($val, 0, $strpos);
$array1[] = substr($val, $strpos+1, strlen($val));
}