3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '"hello world" how are you?'; echo preg_replace_callback('~("[^"]+")|\S+~', function($m) { return isset($m[1]) ? "+" . $m[1] : "+" . $m[0] . "*"; }, $str);

preferences:
25.21 ms | 404 KiB | 5 Q