Jump to content

User:Whilding87/ListReverser

From Wikipedia, the free encyclopedia

List reverser is a small PHP script to aid reversing lists (in non-chronological order primarily).

Source code

[edit]

Name the file as 'reverse.php'

<html>
<head>
<title>List Reverser</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="reverse.php">
  List to reverse<br>
  <textarea name="list" rows="15" cols="100"></textarea>
  <br>
  <input type="submit" name="Submit" value="Submit">
</form>

<?
if ($_POST['list'] != "")
{
  echo "<b>Reversed list</b><br>";
  
  // Split into lines
  $lines    = explode("\n", $_POST['list']);
  $reversed = array_reverse($lines);
  
  for ($i = 0; $i < count($reversed); $i++)
  {
    $output = str_replace("\'", "'", $reversed[$i]);
    echo $output . "<br>";
  }
}
?>
</body>
</html>