Refactor TextCut phpscript