You want to reverse the words or the bytes in a string.
Use strrev() to reverse by byte.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php $username = 'John Doe is anonymous'; echo $username, "<br />"; // reverse by byte echo strrev($username), "<br />"; // reverse by words // break the string up into words $words = explode(' ', $username); // reverse the array of words $words = array_reverse($words); //rebuild the string $username = implode(' ', $words); echo $username, "<br />"; ?> </p> </body> </html> |