Modifie script to use substr() and other features