Home > Article > Backend Development > php string reverse order
Recently, I am writing an FTP search engine for the school network. Due to word segmentation of Chinese strings, I used a combination of forward and reverse methods, and the Chinese strings need to be reversed. I searched online and found that they were all similar and required looping, which I didn’t like very much.
So I read the manual and found that several functions can be used:
str_split() function splits strings into arrays.
array_reverse() accepts an array array as input and returns a new array with the cells in reverse order
implode() function combines the array elements into a string.
The following is the test program:
$str="There are only two basic elements in the world";
echo $str . "
";
$str=implode(array_reverse(str_split($str ,2)));
echo $str;
?>
The output result is:
There are only two basic elements in the world
The two basic kinds of elements exist only in the world