Page 1 of 1

split text string in 2 even parts

Posted: Fri Oct 15, 2004 12:44 am
by potato
Hi,

to make my layout of some text better,i have to split a textstring into 2 even parts.
I've seenon php.net inthe function list,but cant find annything interesting about it.
So i know how to get the count of the words inthe string,buthow to splt the string in a total words/2.

Can anybody help me?

Thanxin advance.

Posted: Fri Oct 15, 2004 3:06 am
by mudkicker
look at wordwrap() function.

Posted: Fri Oct 15, 2004 8:27 am
by potato
The wordwrap functionis not good for this, i think.
You can split a string oncharacters, but not on words.
What i need is something where you split a text into 2 parts, so i need to display the second part also.

Something like this as output:

Code: Select all

echo "<table><tr><td>". $part1."</td></tr>
       <tr><td>".$part2."</td></tr></table>";

Posted: Fri Oct 15, 2004 8:44 am
by mudkicker
then maybe [php_man]str_word_count[/php_man]() help ??

Posted: Sun Oct 17, 2004 7:48 pm
by feyd
search through my posts.. I've posted several times about a [php_man]preg_replace[/php_man] type call that'll return a strings first word after x number of characters.. This can easily be switched to a [php_man]preg_split[/php_man] call to do more useful word wrapping.