3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function reverseHebrew($text) { $words = array_reverse(explode(' ', $text)); foreach ($words as $index => $word) { if (isHebrew($word)) { $words[$index] = mbStrRev($word); } } return join(' ', $words); } function isHebrew($text) { for ($i = 0, $cnt = strlen($text); $i < $cnt; ++$i) { if (ord($text[$i]) > 127) { return true; } } return false; } function mbStrRev($string, $encoding = null) { if ($encoding === null) { $encoding = mb_detect_encoding($string); } $length = mb_strlen($string, $encoding); $reversed = ''; while ($length-- > 0) { $reversed .= mb_substr($string, $length, 1, $encoding); } return $reversed; } $name = "אַבְרָהָם"; $newName = "Alexander Manukian"; echo reverseHebrew($newName);
based on S3DZI
Output for 5.6.38 - 7.3.0rc3
Manukian Alexander