|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 |
|
| 4 | +class ErrorHandler |
| 5 | +{ |
| 6 | + static $m_errstr = ""; |
| 7 | + |
| 8 | + // CATCHABLE ERRORS |
| 9 | + public static function captureNormal($errno, $errstr, $errfile, $errline) |
| 10 | + { |
| 11 | + ErrorHandler::$m_errstr = $errstr . " (" . strval($errno) . ")"; |
| 12 | + |
| 13 | + //echo "CAUGHT: " . ErrorHandler::$m_errstr . " at " . $errfile . " line " . strval($errline) . "<br/>"; |
| 14 | + |
| 15 | + return true; |
| 16 | + } |
| 17 | + |
| 18 | + public static function hasError() |
| 19 | + { |
| 20 | + return strlen(ErrorHandler::$m_errstr) > 0 ? true : false; |
| 21 | + } |
| 22 | + |
| 23 | + public static function getLastError() |
| 24 | + { |
| 25 | + $retVal = ErrorHandler::$m_errstr; |
| 26 | + ErrorHandler::$m_errstr = ""; |
| 27 | + return $retVal; |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | + set_error_handler ( array( 'ErrorHandler', 'captureNormal') ); |
| 32 | + |
| 33 | + |
4 | 34 | $original = $_REQUEST["regex"]; |
5 | 35 | if (is_null($original) || strlen($original) == 0) |
6 | 36 | { |
|
45 | 75 | $html = $html . "</td>\n"; |
46 | 76 | $html = $html . "\t\t</tr>\n"; |
47 | 77 |
|
| 78 | + preg_match($regex, ""); |
| 79 | + $errstr = ErrorHandler::getLastError(); |
| 80 | + if (strlen($errstr) > 0) |
| 81 | + { |
| 82 | + $html = $html . "\t\t<tr>\n"; |
| 83 | + $html = $html . "\t\t\t<td>Error</td>\n"; |
| 84 | + $html = $html . "\t\t\t<td>"; |
| 85 | + $html = $html . htmlspecialchars($errstr); |
| 86 | + $html = $html . "</td>\n"; |
| 87 | + $html = $html . "\t\t</tr>\n"; |
| 88 | + $html = $html . "\t</tbody>\n"; |
| 89 | + $html = $html . "</table>\n"; |
| 90 | + send_json(array("success" => False, "message" => $errstr, "html" => $html)); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
48 | 94 | $html = $html . "\t</tbody>\n"; |
49 | 95 | $html = $html . "</table>\n"; |
50 | 96 |
|
|
53 | 99 | $html = $html . "\t\t<tr>\n"; |
54 | 100 | $html = $html . "\t\t\t<th style=\"text-align:center\">Test</th>\n"; |
55 | 101 | $html = $html . "\t\t\t<th>Target String</th>\n"; |
| 102 | + |
| 103 | + $html = $html . "\t\t\t<th><a href=\"http://www.php.net/manual/en/function.preg-match.php\">preg_match()</a></th>\n"; |
56 | 104 | $html = $html . "\t\t\t<th><a href=\"http://www.php.net/manual/en/function.preg-replace.php\">preg_replace()</a></th>\n"; |
| 105 | + $html = $html . "\t\t\t<th><a href=\"http://www.php.net/manual/en/function.preg-split.php\">preg_split()</a></th>\n"; |
57 | 106 | $html = $html . "\t\t</tr>\n"; |
58 | 107 | $html = $html . "\t</thead>\n"; |
59 | 108 | $html = $html . "\t<tbody>\n"; |
|
78 | 127 | $html = $html . htmlspecialchars($test); |
79 | 128 | $html = $html . "</td>\n"; |
80 | 129 |
|
| 130 | + $html = $html . "\t\t\t<td>"; |
| 131 | + $match = preg_match($regex, $test, $matches); |
| 132 | + if ($match === FALSE) |
| 133 | + { |
| 134 | + $html = $html . "FALSE"; |
| 135 | + } |
| 136 | + else |
| 137 | + { |
| 138 | + $html = $html . strval($match) . "<br/>"; |
| 139 | + $html = $html . "<pre>" . htmlspecialchars(print_r($matches, TRUE)) . "</pre>"; |
| 140 | + } |
| 141 | + $html = $html . "</td>\n"; |
| 142 | + |
81 | 143 | $html = $html . "\t\t\t<td>"; |
82 | 144 | $html = $html . htmlspecialchars(preg_replace($regex, $replacement, $test)); |
83 | 145 | $html = $html . "</td>\n"; |
84 | 146 |
|
| 147 | + $html = $html . "\t\t\t<td><pre>"; |
| 148 | + //$split = preg_split($regex, $test); |
| 149 | + $html = $html . htmlspecialchars(print_r(preg_split($regex, $test), TRUE)); |
| 150 | + $html = $html . "</pre></td>\n"; |
85 | 151 | $html = $html . "\t\t</tr>\n"; |
86 | 152 | } |
87 | 153 |
|
88 | 154 | $html = $html . "\t</tbody>\n"; |
89 | 155 | $html = $html . "<table>\n"; |
90 | 156 |
|
| 157 | + if (ErrorHandler::hasError()) |
| 158 | + { |
| 159 | + $html = $html . "<div class=\"alert alert-error\">" . htmlspecialchars(ErrorHandler::getLastError()) . "</div>"; |
| 160 | + } |
| 161 | + |
91 | 162 | $retVal["html"] = $html; |
92 | 163 |
|
93 | 164 | send_json($retVal); |
|
0 commit comments