Linux-Fan

A simple PHP script to evaluate regular expressions

Aug 11th, 2014
181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $mode = $_GET['mode'];
  3.  
  4. $data = "";
  5. $regex = "";
  6. $replace = "";
  7.  
  8. if($mode == "exec") {
  9.     $data = stripslashes($_POST['data']);
  10.     // Workaround to replace an e which could cause php to execute a command
  11.     $regex = stripslashes(str_replace("e", "x", $_POST['regex']));
  12.     $replace = stripslashes($_POST['replace']);
  13.    
  14.     setcookie("data", addslashes($data));
  15.     setcookie("regex", addslashes($regex));
  16.     setcookie("replace", addslashes($replace));
  17.    
  18.     $_COOKIE["data"] = $data;
  19.     $_COOKIE["regex"] = $regex;
  20.     $_COOKIE["replace"] = $replace;
  21. }
  22.  
  23. echo('<?xml version="1.0" encoding="UTF-8"?>'."\n");
  24. ?>
  25. <html>
  26. <head>
  27. <title>Regex Ausgabe</title>
  28. </head>
  29. <body>
  30. <h2>Regex Ausgabe</h2>
  31. <p>
  32. <?php
  33. if($mode == "exec") {
  34.     $output = preg_replace($regex, $replace, $data);
  35.    
  36.     echo(nl2br(htmlspecialchars($output)));
  37. ?>
  38. </p>
  39. <hr />
  40. <?php
  41.     echo('<h2>Eingegebene Daten</h2>');
  42.     echo("\n<p>\n");
  43.     echo("<b>Regex : </b>".htmlspecialchars($regex)."<br />\n");
  44.     echo("<b>Replace : </b>".htmlspecialchars($replace)."<br />\n");
  45.     echo("<b>Daten : </b><br />\n".nl2br(htmlspecialchars($data)));
  46.     echo("\n</p>\n");
  47. }
  48. ?>
  49. <hr />
  50. <h2>Eingabe</h2>
  51. <p>
  52. <form method="post" action="index.php?mode=exec">
  53. <label for="data">Daten</label>
  54. <br />
  55. <textarea name="data" id="data" rows="20" cols="80">
  56. <?php echo($_COOKIE['data']); ?>
  57. </textarea>
  58. <br />
  59. <label for="regex">Regulärer Ausdruck</label>
  60. <br />
  61. <input type="text" name="regex" id="regex" size="40" value="<?php echo(htmlspecialchars($_COOKIE['regex'])); ?>" />
  62. <br />
  63. <label for="replace">Ersetzungstext</label>
  64. <br />
  65. <input type="text" name="replace" id="replace" size="40" value="<?php echo(htmlspecialchars($_COOKIE['replace'])); ?>" />
  66. <br />
  67. <input type="submit" value="Regulären Ausdruck anwenden" />
  68. </form>
  69. </p>
  70. <hr />
  71. </body>
  72. </html>
RAW Paste Data