Re: splitting a string in half

From: Date: Tue, 31 Jul 2001 07:48:01 +0000
Subject: Re: splitting a string in half
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60349@lists.php.net to get a copy of this message
> I wish to split my databased string in half to be shown on 2 seperate > columns, but also preserve whole words. Is there a function that does this > already? Maybe a quick fix? Hopefully something that doesn't include html > tags as part of the string to split. If it's not that specific then that's > okay. I suppose that this would work if it weren't for the HTML tags inside your text: $text = "Suppose this text was really long."; $half_length = (int) strlen($text) / 2; $split = wordwrap($text, $half_length, "</TD><TD>"); echo "<TABLE><TR><TD>$split</TD></TR></TABLE>"; Now, once you throw HTML tags into your string, you are in a much trickier problem... Don't really see *any* solution for that in a general sense, since somebody could use a tag that spans the entire text, and then you can't break it in half at all... -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#60349) next »