You are here: Re: breaking up strings « PHP Programming Language « IT news, forums, messages
Re: breaking up strings

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]


Удаленная работа для программистов  •  Как заработать на 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

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