Page 1 of 1

Trim set number of characters

Posted: Sat May 13, 2006 7:36 am
by GeXus
If I wanted to trim say 20 characters from the right of a string, how would I do this??

Thank You!

Posted: Sat May 13, 2006 8:12 am
by $phpNut

Code: Select all

$string = substr($string, 0, strlen($string) - 20) // gets the string $string from the beginning to the end -20

Posted: Sat May 13, 2006 9:03 am
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);