Click to See Complete Forum and Search --> : Message size limits


rugrat15834
12-25-2006, 05:35 PM
Hi, how does one limit the size of a post display, that is, when you look at a list of new posts you usually see something like "How does one do something like................." that is, it gives you a taste of what the post is about but does not actually display the whole post at that point. Also, I have a regex question, I put a fowl language filter together which informs a user that the language is unacceptable and needs to be changed as well as showing them what words and the field they appeared in but how, suppose someone took a word which was on the list and instead of just spelling out some bad words, they might use something like s o m e b-a-d w,ord,s to break them up but still get the message across. I am planning on getting a book titled "Mastering Regular Expressions" but till then any help would be much appreciated. Does anyone know of any good tutorials on creating html email?
Thanx and Happy Holidays to all, and to all............. :)

Watts
12-26-2006, 11:24 AM
Here's how I'd do it, but there's more than one way...

$longpost = "blah blah blah a really long post blah blah blah";

$shortpost = substr($longpost, 0, 15); #limits short post to 15 characters

Also, check out some of the perl mods, I bet someone has already made a dirty word mod.


$longpost = "Now is the time for all good men to come to the aid of their country.";

$shortpost = substr($longpost, 0, 15) . "...";

print $shortpost;

#prints out "Now is the time..."

rugrat15834
12-26-2006, 12:48 PM
Thank you much for your time. That way looks easy enough even for me-I believe that is the way I will do it also. I found a file called web-lib.pl which has a dirty word filter with the capabilites of searching for where people might sneak things in that way, I'll piece something together out of it for my own filter. Trouble with most filters is they match on a general basis like
if($input =~ /$wordlist/) and it will take parts of words such as "pass" and find them dirty, with the project I'm working around I plan to make sure the user actually said something bad.
~Happy Holidays!~

CyCo
12-26-2006, 05:53 PM
rugrat15834,

Watts' method works fine, but just in case you need more precision, the method below will ONLY append the three (3) dots IF the string is longer than the length you want to truncate it to.

my $string = "Now is the time for all good men to come to the aid of their country.";
my $truncated_string = sprintf('%s', length $string > 38 ? substr($string, 0, 35) . '...' : $string);
As far as bad words are concerned, a filter would probably work for the average person, but anyone on a mission to sabotage your output, could easily write anything. Unless user input is moderated or subject to approval before being outputted, catching all bad words is virtually impossible.