# Php

**URL:** <https://forum.kirupa.com/t/php/15107>\
**Category:** Uncategorized\
**Created:** [March 10, 2003, 10:41pm UTC](https://forum.kirupa.com/t/php/15107 "2003-03-10T22:41:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fishtank](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fishtank](https://forum.kirupa.com/u/fishtank)\
**Post date:** [March 10, 2003, 10:41pm UTC](https://forum.kirupa.com/t/php/15107/1 "2003-03-10T22:41:52Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 12:45am UTC](https://forum.kirupa.com/t/php/15107/2 "2003-03-11T00:45:30Z")

</div>

i’m not really sure what you mean… can you be more specific?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 3:59pm UTC](https://forum.kirupa.com/t/php/15107/3 "2003-03-11T15:59:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 4:30pm UTC](https://forum.kirupa.com/t/php/15107/4 "2003-03-11T16:30:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 4:34pm UTC](https://forum.kirupa.com/t/php/15107/5 "2003-03-11T16:34:39Z")

</div>

thanks man…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 4:47pm UTC](https://forum.kirupa.com/t/php/15107/6 "2003-03-11T16:47:32Z")

</div>

and when i want to cut off the end of the message?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 5:01pm UTC](https://forum.kirupa.com/t/php/15107/7 "2003-03-11T17:01:26Z")

</div>

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… 😏

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 5:08pm UTC](https://forum.kirupa.com/t/php/15107/8 "2003-03-11T17:08:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 11, 2003, 9:06pm UTC](https://forum.kirupa.com/t/php/15107/9 "2003-03-11T21:06:34Z")

</div>

here’s my shoutbox:

[http://195.230.176.35/media-lab/shoutbox/shoutbox1.html](http://195.230.176.35/media-lab/shoutbox/shoutbox1.html)

plz post there…
