PDA

View Full Version : How do you gauge the characters in variable


zenweezil
06-01-2003, 01:59 AM
I am using this code to olnyly show the first 200 charcters of a variable:

$ShowText = substr($small_story, 0,200);

What I want to do is have it add an elipse ... after the cut off, but only if there is more than the 200 characters.

Ideas?

ACJavascript
06-01-2003, 07:08 AM
Im not quite sure what you mean by Elipse but you could do somthing like this..


if($small_story.length>=200){
//Code for if small_story is equal to or greater then 200
}else{
//Code for if small_story is less then 200
}


Havn't tested it hehehehe :D

zenweezil
06-01-2003, 01:41 PM
It doesn't get much easier then that...man where was my head.

Thanks, i'm sure that will do it.

zenweezil
06-03-2003, 02:07 AM
What if instead of displaying just the first 200 characters you wanted it to display until the first break in the text.

So it would only display until it reaches the <BR><BR> codes in the text.

How would that work? A split?

@newdisplay=split(/<BR><BR>/, $small_story);

Does that code look right? I guess I might be answering my own questions here.

ACJavascript
06-05-2003, 06:12 PM
So your saying for an example:

someone types in a textarea and once they put in <BR><BR> it cuts whatever else they put in??

or someone types in a textarea and once it reaches 200 <BR><BR> is put in and everything else is cut??

zenweezil
06-07-2003, 05:58 AM
The goal was to show the first paragraph on the home page and offer a link to the rest without having to enter the first paragraph as a different variable in the orgininal form.

This worked:

@display = split(/<BR><BR>/, $small_story);
$showtext = $display[0];