Page 1 of 1

Im having problems with wordwrap()

Posted: Sun Oct 28, 2007 2:14 pm
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]

Posted: Sun Oct 28, 2007 2:33 pm
by feyd
How would the "cut" understand 790 pixels? PHP doesn't care about pixels or measurements in general.

Posted: Sun Oct 28, 2007 2:59 pm
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)

Posted: Sun Oct 28, 2007 3:10 pm
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?

Posted: Sun Oct 28, 2007 3:19 pm
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

Posted: Sun Oct 28, 2007 4:07 pm
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.

Posted: Sun Oct 28, 2007 10:28 pm
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?