Text Overflow

Support, Snippets & Projects

Moderators: Moderator, Global Moderator

Post Reply
radar
Hero Member
Hero Member
Posts: 632
Joined: Wed Jun 16, 2004 5:37 pm

Text Overflow

Post by radar »

I'm currently working on a personal side-project and I would like to know how to get a text box to keep its width without expanding itself because some idiot has not learnt how to use the space bar. I've also found this problem on killablogs if someone posts a long comment it would turn out to be something similar to

[img]http://www.frozenplague.net/img/phpspam.png[/img]

As you can see by this screenshot, it pushes the content over to the right and "defaces" the site. Is there a way to get the php to recognise that the word is too long to belong in the english language and insert a <br> somewhere? So instead of lollollollollollollollollollollollollollollollollollollollollol you would have

lollollollollollollollollollollollol
lollollollollollollollollollollollol
Vercz
Hero Member
Hero Member
Posts: 1915
Joined: Sat May 08, 2004 11:13 pm

Text Overflow

Post by Vercz »

well...if you can work out how to define $string properly /blum.gif' class='bbc_emoticon' alt=':P' /> ..this should work /biggrin.gif' class='bbc_emoticon' alt=':D' />

Code: Select all

<?
$Length = 5;
$string = 'blog_post';

if(strlen($string) > $Length){
    preg_match('/[a-zA-Z0-9]{0,'.$Length.'}/', $string, $t);
    $Output = $t . '<br>';
}
?>
[/color]
Last edited by Vercz on Tue Feb 15, 2005 3:29 am, edited 1 time in total.
Image

Image
Scott
Administrator
Administrator
Posts: 1651
Joined: Sun Apr 25, 2004 6:08 am

Text Overflow

Post by Scott »

[url="http://aidan.dotgeek.org/lib/?file=function.str_chop.php"]Also useful[/url]
Post Reply

Return to “PHP &amp; MySQL”