Home  >  Article  >  Backend Development  >  php string reverse order

php string reverse order

巴扎黑
巴扎黑Original
2016-11-21 14:34:124400browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn