1.5. Reversing a String by Word or Character1.5.2. SolutionUse strrev( ) to reverse by character:
To reverse by words, explode the string by word boundary, reverse the words, then rejoin:
1.5.3. DiscussionReversing a string by words can also be done all in one line:
1.5.4. See AlsoRecipe 18.8 discusses the implications of using something other than a space character as your word boundary; documentation on strrev( ) at http://www.php.net/strrev and array_reverse( ) at http://www.php.net/array-reverse.
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|