Home >>PHP Programs >How to reverse words in a string
<?php extract($_REQUEST); if(isset($reverse)) { $str = $words; $i = 0; $temp=null; $out=null; while(@$d = $str[$i]) { if( $d == " ") { $out = " ".$temp.$out; $temp = ""; } else { $temp.=$d; } $i++; } echo $temp.$out; } ?> <!DOCTYPE html> <html> <head> <title>Reverse Words in PHP</title> </head> <body> <form method="post"> <table border="1"> <tr> <th>Enter Your Words <input type="text" name="words" placeholder="enter your words here"> <<input name="reverse" type="submit" value="Reverse My Word" />