Reply to Re: Adding line breaks to a variable dynamically

Your name:

Reply:


Posted by Rik on 12/16/06 01:43

Geoff Berrow wrote:
> Message-ID: <3e4cb$458343c7$8259c69c$2192@news2.tudelft.nl> from Rik
> contained the following:
>
>> $array = split(' ',$string);
>> $newstring = '';
>> $rows = 3;
>> while($rows >= 1){
>> $newstring .= implode('
>> ',array_splice($array,0,floor(count($array)/$rows--))).'<br>';
>> }
>> echo $newstring;
>
> That's a bit complicated for you Rik...
>
> $array=explode(" ",$linestring);
> for($i=0;$i<count($array);$i++){
> echo(($i+1)%3===0)?$array[$i]." <br>\n":$array[$i]." ";
> }

Yup, for some reason I've decided I hate variable counters, don't know why
:-). It doesn't hurt to try different methods either.

Then again, your answer is flawed :P

It's not three (or #n) words in a row, but an arbitrary amount of words
split in #n rows.

That's a bit more complexity if we want to divide the remainder over the
rest of the rows... Easiest way to do that is to recalculate the number of
words we should use, hence the variable length splice.
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация