Trim text down for the web

September 5, 2004 at 4:02 pm Leave a comment

I was busy working on the routine to display the results a search in my FAQ web application when I realized that I needed to cut the results short… This was painfully obvious during my testing as one of my test questions has an extremely long answer. Displaying each matching question and answer in its entirety would be a bit much…

Of course, there are simple ways of cutting your text short, but PHP’s built-in functions aren’t very smart about it and will cut the text EXACTLY where you tell it to. This can result in a topic like “Fun things to do with sextants”, if trimmed at 25 characters, to be “Fun things to do with sex”… This type of thing could offend some site visitors, and would likely embarrass some site owners.

In my question to keep from re-inventing the wheel, I ran across a good free routine released by the fine folks at Silver Orange. It intelligently trims text along spaces and accounts for a wide variety of issues that can come up. I was able to easily drop it right into my FAQ project and it works beautifully. I highly recommend it!


Entry filed under: PHP.

SiteCheck Slow progress

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


September 2004
« Aug   Dec »

Most Recent Posts

%d bloggers like this: