split text string in 2 even parts

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

split text string in 2 even parts

Post 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.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

look at wordwrap() function.
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post 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>";
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

then maybe [php_man]str_word_count[/php_man]() help ??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply