substr get last 10 characters code example Example: take last four digits php $newstring = substr($dynamicstring, -7);