Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

PHP: Truncate from Left

Using PHP, how can I truncate text on the left side?
<?php

$str = 'This is a test and only a very long test to see if this works'

echo truncate_left($str,10);
// should echo 'this works';


function truncate_left($str, l) {
return ($str);
}

?>

Open in new window

Avatar of sshah254
sshah254

substr($str, 0, 10)

will return 10 characters, starting from 0.

Ss
Avatar of hankknight

ASKER

Yea, but I want to truncate in the other direction.

This is a test and only a very long test to see if this works
Should become
this works

Test the code I posted and you will see what I mean.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial