PHP port of SMAZ text shortening algorithm