Re: php solution to html problem

From: Date: Thu, 25 Aug 2005 08:26:54 +0000
Subject: Re: php solution to html problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-221333@lists.php.net to get a copy of this message
On Wed, August 24, 2005 9:09 am, Ross wrote: > I have a table which I put php data from a database. > > If i have a name 'thisisaveryverylongfirstname' the table stetches to > fit > the name. Is there any way I can force it to wrap to a fixed width of > 100px?? > > If I put a space in <BR> the text wraps. How can I do this at > character 30 > of the string? > > Or any other suggestions... PHP's wordwrap function may have an optional argument to FORCE it to never be wider than X characters, but I don't think so... You could write your own wordwrap function in about an hour, max. Or take one of the umpteen wordwrap functions from before PHP had a built-in wordwrap function. If you are using CSS, and if you know the font and font-size it will display in, I guess you could even fire up GD or PDF or something and use the string length functions there with the same font and font-size and figure out exactly where you should break up the string... I'd cheat a little conservative if you REALLY need it to be no more than 100px exactly, because I'm guessing differences in rendering will make the text wider/narrower than GD thinks when the browser renders it. Actually, if you go to THAT much effort, and if it's really crucial, maybe you should display the text as image. Ugh. Still, if it HAS to be 100px or less, you could do that, and be CERTAIN of the width. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#221333) next »