forked from monperrus/crawler-user-agents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.php
More file actions
30 lines (26 loc) · 766 Bytes
/
validate.php
File metadata and controls
30 lines (26 loc) · 766 Bytes
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
<?php
// checks that the patterns work in PHP's preg_match
$data = json_decode(file_get_contents('crawler-user-agents.json'), true);
$patterns = array();
foreach($data as $entry) {
$patterns[] = $entry['pattern'];
if (isset($entry['instances'])) {
foreach($entry['instances'] as $ua_example) {
if (!preg_match('/'.$entry['pattern'].'/', $ua_example)) {
throw new Exception('pb with '.$entry['pattern']);
}
}
}
}
// testing with a giant regexp
$regexp = implode('|', $patterns);
foreach($data as $entry) {
if (isset($entry['instances'])) {
foreach($entry['instances'] as $ua_example) {
if (!preg_match('/'.$regexp.'/', $ua_example)) {
throw new Exception('pb with '.$entry['pattern']);
}
}
}
}
?>