Gossamer Forum
Home : Products : DBMan : Customization :

How to limit characters when displaying...

Quote Reply
How to limit characters when displaying...
Hello JP,
I have a question on how to limit a number of character on text area?

What I mean is that I sued your long//short mod, and I thought it would be great for me personaly if I could display my $rec{'Detail'} in the short displayed record. But it is imposible to display all the text from the text area, but it would be good if we can show only let say 150 characters max for summary.

I hope you get my point.
Any help would be appreciate it.

Thanks
Quote Reply
Re: How to limit characters when displaying... In reply to
I would like to implement this too. Anybody have any ideas on how to achieve this...?
Quote Reply
Re: How to limit characters when displaying... In reply to
After sub HTML_RECORD grabs your $rec{Detail}, instead of sending to print, pass it to a piece of code with reg expressions to match the first 150 characters then print that to the page.
I,m not an expert on reg expressions, but if you need help with it I could come up the code after thinking about it.
Quote Reply
Re: How to limit characters when displaying... In reply to
DarinB,

Thank you for the input, yes please I do need your help Smile
I am not an expert in reg exp either, but willing to try with your help.

Thank you for your kindness.

Santana
Quote Reply
Re: How to limit characters when displaying... In reply to
Hello DarinB,

Still no luck, it appears "1" when I viewed. Frown

Well, thanks anyway..., and really appreciate it if you or any other could tell me and web dog how to implement this matter.

Thanks
Quote Reply
Re: How to limit characters when displaying... In reply to
Santana,

Try this:

$output = ($rec{'Detail'} =~ /.{0,150}/s);

Where $output would be the variable to print in place of $rec{Detail}. I only checked syntax, I couldn't tell you if it will work.
You may need to change the variable name.
Quote Reply
Re: How to limit characters when displaying... In reply to
O.K. I "think" I know where we are going.

You said, "appears 1". Is that the number 1 or one letter.

If it was the number 1 then it was returning the number of matches to $output. Try this:

($rec{'Detail'} =~ /^.{150}/s);

We will get this yet, right!
Knowledge comes from experience(mistakes)!

[This message has been edited by DarinB (edited November 17, 1999).]
Quote Reply
Re: How to limit characters when displaying... In reply to
Hi,

When I used:
$output = ($rec{'Detail'} =~ /.{0,150}/s);
then, it appears "1" (number 1) for the output.
For ($rec{'Detail'} =~ /^.{150}/s);
the output is just blank.

And yes, we will get this one Smile

With no knowledge on reg. exp. I tried to add or remove characters on that expression, but I got error 500.
DarinB, I'd like to ask a question, and you can just answer it in short answer Smile
How do you decide to use characters like:
/s, ^{ ?
It is amazing that you familiar with those characters and the fuctions.

Well, thanks very much.
Quote Reply
Re: How to limit characters when displaying... In reply to
Santana,

Sorry for the lateness for the reply, setting up an auction site for a client.

As for which characters to use, some characters have special meaning to PERL when used in REG EXP. My suggestion is to get a Perl book that covers REG EXP like Programming Perl from O'Reilly.

I just noticed a mistake on my part. If you used ($rec{'Detail'} =~ /^.{150}/s); with the parentheses it would return blank, take the parentheses out and try it.
Quote Reply
Re: How to limit characters when displaying... In reply to
Hello DarinB
Thanks for the respond...

Well, it still didn't work. Frown
It shows "1" (number 1) again when I take out the parentheses.

Then, I tried to remove each character one by one, it still no luck.

BUT, when I used only:
$rec{'Detail'} =~ /^.{150}/s;
then, it shows shows the detail, but full detail (not 150 characters)

when I used:
$output= $rec{'Detail'} =~ /^.{150}/s;
it shows "1"

Well, I'll try to get the books, hopefully I can get it.
I'll inform you when I make it Smile
But, you are very welcome to advise me anything Smile

Thank you very much.

Santana
Quote Reply
Re: How to limit characters when displaying... In reply to
Santana,
hang in there, I'm working on somthing similar in the perl forum, where I need to limit the length of a string to 10 charactors. I havent tried out there new suggestion yet, but if you want to follow the progress its at
www.gossamer-threads.com/scripts/forum/resources/Forum8/HTML/000877.html
The perl forum is a very interesting place.

Bob

[This message has been edited by lanerj (edited November 21, 1999).]

[This message has been edited by lanerj (edited November 21, 1999).]

[This message has been edited by lanerj (edited November 21, 1999).]
Quote Reply
Re: How to limit characters when displaying... In reply to
Oh My God!
Thanks lanerj !!! IT WORKS!
I am glad to see your post, and i did with GClemmons advice which is:

$ic = $rec{'Detail'});
$ic = substr($ic, 0, 100) if (length($ic) > 100);
but the problem is, well is not that big problem, it takes exactly 100 characters, no matter the word is still running. for example:
at the 95th character, there is a word of "payable", then it returns "payab" because the "b" is the 100th character. Well, is not perfect but I can live with that for a while.

Thank you very much for DarinB who helps me a lot from the beginning, to lanerj for posting the recommendation link, to GClemmons of course, and JPDeni! Smile

thanks all


Quote Reply
Re: How to limit characters when displaying... In reply to
You could ask the guys at the perl forum for the fix for that.

Bob