The list looks like:
Lorem ipsum dolor sit amet,
consectetur adipisicing elit,
sed do eiusmod tempor
...
I want to indent all words like this:
Lorem ipsum dolor sit amet,
consectetur adipisicing elit,
sed do eiusmod tempor
(or at least the first column)
I've managed to do this using arrays and str_pad
:
$lines = explode("
", $text);
$counts = array();
foreach($lines as $line){
$words = explode(' ', $line);
foreach($words as $index => $word){
if(!isset($counts[$index]) || $counts[$index] < strlen($word))
$counts[$index] = strlen($word);
}
}
$text = '';
foreach($lines as $line){
$words = explode(' ', $line);
foreach($words as $index => $word)
$text .= str_pad($word, $counts[$index], ' ' , STR_PAD_RIGHT) . ' ';
$text .= "
";
}
but because the text is very large it uses quite a lot of memory. Is there any other way I can do this, without splitting the text in arrays?