PDA

View Full Version : php



fishtank
March 10th, 2003, 05:41 PM
how can i reduce the size of a variable printed?

for example, i would like to make it possible to the user to controll the length of a displayed text...

Jubba
March 10th, 2003, 07:45 PM
i'm not really sure what you mean.... can you be more specific?

fishtank
March 11th, 2003, 10:59 AM
for example:

$message is loaded from a textfile.

it consists of ABCDEFGHJKLMNOPQRSTUVW.

i want the script to print the script only the number of letters the user sets, for example 5 => the script prints ABCDE

Marz
March 11th, 2003, 11:30 AM
You would use this:

$offset = number user specifies.
$message = the message being cropped.

print substr($message, $offset);

or you can say.

$croppedmsg = substr($message, $offset);
print "$croppedmsg":

There ya go man :) You can also put in a negative number to return a set number of characters from the end of the string towards the front.

fishtank
March 11th, 2003, 11:34 AM
thanks man...

fishtank
March 11th, 2003, 11:47 AM
and when i want to cut off the end of the message?

fishtank
March 11th, 2003, 12:01 PM
wh0000!!!!

thanx m8!!!!

with that my shoutbox worx... thanx man, i love you... uhm, ok, its not really love, but... you know what i mean... :smirk:

Marz
March 11th, 2003, 12:08 PM
Just use positive numbers.... Or do you mean.. If you wanna take off a certain number of characters starting from the end?

I don't see any direct methods of doing that so I'm guessing it would involve some rigging up to gte it to work right..

I'd suggest just using whatcha got here and Or... You could always do it this way...


$length = strlen($message);
$offset = number inputted by person
$cropnum = $length - $offset;

$croppedmsg = substr($message, $cropnum);

That should do the trick for you.

fishtank
March 11th, 2003, 04:06 PM
here's my shoutbox:

http://195.230.176.35/media-lab/shoutbox/shoutbox1.html

plz post there...