Im having problems with wordwrap()

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
Darkzero
Forum Newbie
Posts: 18
Joined: Thu Oct 25, 2007 8:48 pm

Im having problems with wordwrap()

Post by Darkzero »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The syntax is right, I know that. It technically works, it cause it puts a <br /> tag every 115 characters. But, the 'cut' part of it's not working. Neither is my CSS overflow, for that matter.

Here's a little PHP snippet..

Code: Select all

$message = wordwrap($messageb,115,"<br />\n",TRUE);
Cut's set to TRUE, so it should work, but it's not and i can't understand why. The page it's being used on is:
http://www.project-dz.com/list.php

If I input something like "WWWWWWWWWWWWWWWWWWW..ect" It breaks every 115 characters, but the cut fails and it stretches the page anyways. (sorry for being redundant, im just trying to make my problem clear)

Here's my css, i think it might have something to do with it:

Code: Select all

table.list {
background-color: transparent;
width: 1000px;
border: medium double #FFFFFF;
overflow: hidden;
}

td.msg {
vertical-align: top;
width: 790px;
overflow: hidden;
}
td.side {
font: caption;
width: 190px;
vertical-align: top;
overflow: hidden;
}
td.post {
width: 5px;
vertical-align: top;
}
The td "msg" is set to 790 px, so the cut should put a break at 790.. I don't understand why it isn't working :\


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How would the "cut" understand 790 pixels? PHP doesn't care about pixels or measurements in general.
Darkzero
Forum Newbie
Posts: 18
Joined: Thu Oct 25, 2007 8:48 pm

Post by Darkzero »

feyd wrote:How would the "cut" understand 790 pixels? PHP doesn't care about pixels or measurements in general.
Cut: Optional. Specifies whether words longer than the specified width should be wrapped. Default is FALSE (no-wrap)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You realize that's number of characters, not width in pixels, because PHP has no idea what width the end result will be, right?
Darkzero
Forum Newbie
Posts: 18
Joined: Thu Oct 25, 2007 8:48 pm

Post by Darkzero »

feyd wrote:You realize that's number of characters, not width in pixels, because PHP has no idea what width the end result will be, right?
OH. I had read that wrong, I thought it meant the width of the table or the element it's in, not the amount of characters.. lol sorry.

Well, then is there anyway to restrict the amount of characters in a single word, but not the amount inthe entire sentence?

IE, i want someone to be able to say something like..
"Hi my name's john, I live in washington, DC, and I get bored easily so i'm writing this small paragraph about absolutely nothing. I'm now twenty-four, living with my girlfriend and her sister. ect ect ect"
The first line of that contains 136 characters. 136 W's in one word would stretch the page.. So is there anyway i could restrict just the word length, and not the entire sentence length?

IE, the 'sentence':
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW


Would break off every 30 characters and show as:
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW&NBSP;WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW&NBSP;WW
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

You could write a function to accept the input as an argument, split it into an array of "words", then cycle through the words and insert breaks whenever the word length exceeds some number, then put the words back together with spaces in between and return the possibly modified input.
Darkzero
Forum Newbie
Posts: 18
Joined: Thu Oct 25, 2007 8:48 pm

Post by Darkzero »

califdon wrote:You could write a function to accept the input as an argument, split it into an array of "words", then cycle through the words and insert breaks whenever the word length exceeds some number, then put the words back together with spaces in between and return the possibly modified input.
..I just started learning php two weeks ago. lol. I don't yet understand how to do that :\

Link that might help?
Post Reply