Posted by Craig Taylor on 07/30/06 02:29
Ian Davies wrote:
> Hello
> I have a string of varying length, lets call it $mystring.
> I wish to break it up and put it in the following form
>
> echo"<span
> class='myclass'>".1st_30chars_$mystring_to_nearest_word."<br>".2nd_30chars_$
> mystring_to_nearest_word."<br>".....etc....last_lot_of_chars_of_$mystring."<
> /span>";
>
> does anyone know how to do this
> Ian
Someone else has already posted referencing the wordwrap function; if
you wish to do it yourself - ie: more customization than wordwrap can
give you - use the following psuedo-code that takes advantage of strtok
(note: I haven't validated this hence it's psuedo-code not 'true' code
):
$x = 'sentance of some length';
$y = strtok( $x, ' ' );
$curpos = 0;
while( !( $y == null ) )
{
echo $y;
if( strlen($y) + $curpos > 30 )
{
echo '<br>';
$curline = 0;
}
$y = strtok( $x );
}
- Craig Taylor
http://www.ctalkobt.net
Navigation:
[Reply to this message]
|