Skip to content

Commit b0df90f

Browse files
committed
hacked in some error handling
1 parent b923f39 commit b0df90f

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

www/test.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
<?php
22

33

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+
434
$original = $_REQUEST["regex"];
535
if (is_null($original) || strlen($original) == 0)
636
{
@@ -45,6 +75,22 @@
4575
$html = $html . "</td>\n";
4676
$html = $html . "\t\t</tr>\n";
4777

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+
4894
$html = $html . "\t</tbody>\n";
4995
$html = $html . "</table>\n";
5096

@@ -53,7 +99,10 @@
5399
$html = $html . "\t\t<tr>\n";
54100
$html = $html . "\t\t\t<th style=\"text-align:center\">Test</th>\n";
55101
$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";
56104
$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";
57106
$html = $html . "\t\t</tr>\n";
58107
$html = $html . "\t</thead>\n";
59108
$html = $html . "\t<tbody>\n";
@@ -78,16 +127,38 @@
78127
$html = $html . htmlspecialchars($test);
79128
$html = $html . "</td>\n";
80129

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+
81143
$html = $html . "\t\t\t<td>";
82144
$html = $html . htmlspecialchars(preg_replace($regex, $replacement, $test));
83145
$html = $html . "</td>\n";
84146

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";
85151
$html = $html . "\t\t</tr>\n";
86152
}
87153

88154
$html = $html . "\t</tbody>\n";
89155
$html = $html . "<table>\n";
90156

157+
if (ErrorHandler::hasError())
158+
{
159+
$html = $html . "<div class=\"alert alert-error\">" . htmlspecialchars(ErrorHandler::getLastError()) . "</div>";
160+
}
161+
91162
$retVal["html"] = $html;
92163

93164
send_json($retVal);

0 commit comments

Comments
 (0)