Home >Backend Development >PHP Tutorial >How to reverse php string by word_PHP tutorial
This article describes the method of reversing php string according to words. Share it with everyone for your reference. The specific analysis is as follows:
The following php code can reverse and output the string according to words. In fact, the string is separated into arrays according to spaces, and then the array is reversed and output
<?php $s = "Reversing a string by word"; // break the string up into words $words = explode(' ',$s); // reverse the array of words $words = array_reverse($words); // rebuild the string $s = implode(' ',$words); print $s; ?>
The output results are as follows:
word by string a Reversing
I hope this article will be helpful to everyone’s PHP programming design.