Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.116.88.132
<?php
function str_splitf($longString,$maxLineLength)
{
$arrayWords = explode(' ', $longString);
// Max size of each line
//$maxLineLength = 30;
// Auxiliar counters, foreach will use them
$currentLength = 0;
$index = 0;
foreach($arrayWords as $word)
{
// +1 because the word will receive back the space in the end that it loses in explode()
$wordLength = strlen($word) + 1;
if( ( $currentLength + $wordLength ) <= $maxLineLength )
{
$arrayOutput[$index] .= $word . ' ';
$currentLength += $wordLength;
}
else
{
$index += 1;
$currentLength = $wordLength;
$arrayOutput[$index] = $word;
}
}
return $arrayOutput;
}
?>
|