Help - Search - Members - Calendar
Full Version: Is there a way to shorten long words?
Movable Type Community Forum > Additional Resources > Tips and Tricks
elvissinatra
I'm familiar with the trim_to attribute but I'd like to be able to set a maximum length for each word? The reason I want to do this is because I want to show recent comments on the front page, and if someone posts a long URL in their comment, it messes up my CSS/div-based layout. As pointed out on this site, "IE will expand the divs to contain the content, which violates the specs, and other browsers will let too wide content spill outside of the div."

Ideas?
noelgreen
Why not put a div inside a div? Make the outside one expandable browser size, then the inside one could be set to a width of the outer one. That would wrap the words rather than expand them.

I've never had the problem of things expanding divs.

In fact, I would like to know the same thing for the opposite reason. I need the subject lines posted by my authors on MonkeyType.org to shorten, thereby not being this long obtrusive thing some of them like to post as titles.

Hope the div inside div thing helps.
oscarf
You can wrap strings at a certain width with php if you are running php. I use this to wrap incoming search strings which I display in my sidebar.
elvissinatra
Noel, I have a two-column layout with a fixed width second column (250px). I don't want the second column to expand at all. The words will wrap as they should as long as they are short words. My issue is with very long "words" such as URLs.

For example, I have a Recent Comments section on a page, and there's one of the entries looks like this:

QUOTE
Jake on Jack White: "Nobodygirl, here's the permanent link to that: http://www.thesmokinggun.com/archive/jackw...ite1.html"


Well, what happens is that big long "word" (http://www.thesmokinggun.com/archive/jackwhite1.html) messes up my layout by expanding the second column to fit that word. (This is only in IE; Mozilla truncates the text, as it should per the spec.)


Oscar, I assume you are referring to the wordwrap function in php? In an MT template, how can I do the equivalent of saying:

CODE
<?php echo(wordwrap('<$MTCommentBody remove_html="1"$>', 20, " ", 1)) ?>;


Because that doesn't seem to work...
elvissinatra
I figured it out.

CODE
<?php $text='<MTFirstNWords n="20" append="..."><$MTCommentBody  remove_html="1" encode_js="1"$></MTFirstNWords>'; $newtext = wordwrap( $text, 30, " ", 1); echo "$newtext"; ?>


Thanks for your help, everybody!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.