-
Notifications
You must be signed in to change notification settings - Fork 1
/
validator-nu.php
executable file
·39 lines (29 loc) · 989 Bytes
/
validator-nu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env php
<?php
#
# Make sure to chmod +x this
#
$html_patterns = array();
$html_patterns[0] = '/<code>/';
$html_patterns[1] = '/<\/code>/';
$html_patterns[2] = '/</';
$html_patterns[3] = '/>/';
$html_replace = array();
$html_replace[0] = '';
$html_replace[1] = '';
$html_replace[2] = '<';
$html_replace[3] = '>';
$fileName = $argv[1];
$validatorAddress = $argv[2];
$theCall = sprintf("curl -sF 'uploaded_file=@%s' %s", $fileName, $validatorAddress);
exec($theCall, $validatorOutput);
$validationString = implode($validatorOutput);
$validationString = preg_replace($html_patterns, $html_replace, $validationString);
$error_pattern = "/<li class=\"error\">(.*?)<span>(.*?)<\/span>(.*?)<span class=\"last-line\">(.*?)<\/span>(.*?)<\/li>/";
preg_match_all($error_pattern, $validationString, $errors);
$outErrors = "";
for ($i = 0; $i < count($errors[2]); $i++) {
$outErrors = $outErrors . $errors[4][$i] . " :-: " . $errors[2][$i] . "\n";
}
print_r($outErrors);
?>