3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function replace_spaces ($text) { function replacement ($matches) { return str_replace ($matches[1], ' ', '&nbsp;').' '; } return preg_replace_callback ('/( +) /', 'replacement', $text); } echo replace_spaces('hello world');
based on RlHDG
Output for 4.3.0 - 7.2.0
hello world