I am trying to reverse a string containing Hebrew from RTL to LTR, but my coding attempt is reversing brackets as well. `strrev()` didn't work because it does not actually work for UTF8 strings. So I wrote a custom function, below is my code:

```
$str = 'תירס גדול A-10 (פרי גליל)';
function utf8_strrev($str)
{
    $arr = '';
    $words = explode(" ", $str);
    $start_tag = '(';
    $end_tag = ')';
    foreach ($words as $word)
    {
        if (preg_match("/\p{Hebrew}/u", $word))
        {
                preg_match_all('/./us', $word, $ar);
                echo print_r($ar[0]);
                echo '<br>';

                $arr = join('', array_reverse($ar[0])) . " " . $arr;
        } else
        {
            preg_match_all('/./us', $word, $ar);
            $arr = join('', $ar[0]) . " " . $arr;
        }
    }
    return $arr;
}

```

OUTPUT :

```
)לילג ירפ( A-10 לודג סרית 

```

what it should be:

```
(לילג ירפ) A-10 לודג סרית

```