Is it possible to reverse only the letters in a string?
For instance if I have the word $word = "word,!";
I need the result to be $result = "drow,!";
I tried using strrev
, but it reverses the punctuation marks too.
$word = "word,!pineapple--pizza";
$revd = preg_replace_callback('#([A-Za-z]+)#', 'rev_first', $word);
function rev_first($matches){
return strrev($matches[1]);
}
Is this what you're looking for?