Refactor TextCut php scripts