//ads:
?>
Create a new line whenever an array value reaches more than 10 characters
PHP Snippet 1:
$caption = "im trying to figure out how to create a new line whenever an array value reaches more than 10 characters";
$lineCharlimit = 10;
$captionWordsArray = explode( " " ,$caption );
$line = '';
foreach( $captionWordsArray as $index => $word )
{
if( strlen( $line .$word ) > $lineCharlimit )
{
echo $line ,'<br>';
$line = $word;
}
else
{
$line .= ( $line == '' ? '' : ' ' ) .$word;
}
}
echo $line;
PHP Snippet 2:
im trying
to figure
out how to
create a
new line
whenever an
array value
reaches
more than
10
characters
PHP Snippet 3:
im trying to
figure out how
to create a
new line whenever
an array value
reaches more
than 10 characters
PHP Snippet 4:
$caption = "im trying to figure out how to create a new line whenever an array value reaches more than 10 characters";
$lineCharlimit = 10;
$captionWordsArray = explode( " " ,$caption );
$line = '';
foreach( $captionWordsArray as $index => $word )
{
$line .= ( $line == '' ? '' : ' ' ) .$word;
if( strlen( $line ) > $lineCharlimit )
{
echo $line ,'<br>';
$line = '';
}
}
echo $line;