2 letters from the right

echo $myString;

The code above produces “my” which is 2 letters from the left.
I like to produce “ng” which is 2 letters from the right.

instead of 0, use srtlen() minus however many characters from the end you need as your starting point in substr()

The code below is one of trials for it, but it causes an error.

echo $myString;

How can I fix the code above?

Try this:
$myString=substr($myString, -2);

rtfm (read the fine manual) :slight_smile:


or another way

$myString = 'mystring';
echo substr($myString,strlen($myString)-2);

but lampcms’s way is shorter