Trim set number of characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Trim set number of characters

Post by GeXus »

If I wanted to trim say 20 characters from the right of a string, how would I do this??

Thank You!
User avatar
$phpNut
Forum Commoner
Posts: 40
Joined: Tue May 09, 2006 5:13 pm

Post by $phpNut »

Code: Select all

$string = substr($string, 0, strlen($string) - 20) // gets the string $string from the beginning to the end -20
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

$phpNut wrote:

Code: Select all

$string = substr($string, 0, strlen($string) - 20) // gets the string $string from the beginning to the end -20
That's the same as:

Code: Select all

$string = substr($string, 0, -20);
Post Reply