Php Loop Through String Javascript Substring