<?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;
You have javascript disabled. You will not be able to edit any code.