3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "این متن فارسی است and this is !!! in English این خط بعدی است و this is going to be continued..."; $newStr = preg_replace_callback('/\w.*(?=\w|\b)/', function (array $m) { return implode(" ", array_reverse(explode(" ", $m[0]))); }, $string); echo $newStr;

preferences:
177.95 ms | 407 KiB | 5 Q