<?php $str = '123 1234 12345 121212'; $arr = explode("\n", $str); foreach($arr as $num){ echo strrev($num).'<br />'; } ?>