3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = '12345678'; $head = substr($str, 0, strlen($str)%3); $str = substr($str, strlen($head)); $str = preg_replace( '/(.{3})/', ' $1', $str ); echo trim($head . $str); //string(10) "12 345 678"
based on j3eEM
Output for 5.6.0 - 7.2.6
12 345 678