You are here: Adding line breaks to a variable dynamically « PHP Programming Language « IT news, forums, messages
Adding line breaks to a variable dynamically

Posted by howarthc@gmail.com on 12/16/06 00:12

OK - here is what I want to do - but I am lost how to do it.

I have a variable

$mystring = "one two three four five six seven eight nine"

This variable $mystring can be 4 words long or it could be 50 words
long it is totally variable. What I want to do is take the number of
words in $mystring, divide by three and insert a <br> at the end of
each "line".

Example: $mystring = "one two three four five six seven eight nine"

Convert to:
one two three<br>
four five six<br>
seven eight nine<br>

Example: $mystring = "one two three four five six seven eight nine ten
eleven twelve"

Convert to:
one two three four<br>
five six seven eight<br>
nine ten eleven twelve<br>

I know I can use explode or strip with a field seperator of " " to
break the variable into component parts - but my non-programmer brain
is confused how I would do this.

Any assistance or pointers would be great... cheers,

Chris

 

Navigation:

[Reply to this 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

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