V
V
Vlad2015-10-23 12:10:29
PHP
Vlad, 2015-10-23 12:10:29

How to write a word backwards in php?

Hello.
Can you please tell me how to write the word in reverse in php?
hello
tewirp

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-23
@Sc0undRel

echo strrev("String"); //gnirtS
As for UTF-8 ( echo strrev("Строка"); //�коЀтѡ�), you can play with the encoding:

function str_reverse($string){
   return iconv('utf-16be', 'utf-8', strrev(
      iconv('utf-8', 'utf-16le', $string)
   ));
}

or directly in the forehead:
function str_reverse($string){
   return implode("", array_reverse(
      str_split($string)
   ));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question