Mercurial > hg > webaudioevaluationtool
comparison php/get_tests.php @ 2283:169f08dc9634
Fix for #25, PHP uses the array() function rather than the [] initialiser (only supported if PHP >= 5.4)
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Fri, 22 Apr 2016 09:34:34 +0100 |
parents | 760719986df3 |
children | d26623bd65e0 |
comparison
equal
deleted
inserted
replaced
2281:185232d01324 | 2283:169f08dc9634 |
---|---|
3 Get Tests | 3 Get Tests |
4 | 4 |
5 This script returns the XML test names available, plus the number of tests | 5 This script returns the XML test names available, plus the number of tests |
6 */ | 6 */ |
7 | 7 |
8 //http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php | 8 include "rel2abs.php"; |
9 function rel2abs($rel, $base) | |
10 { | |
11 /* return if already absolute URL */ | |
12 if (parse_url($rel, PHP_URL_SCHEME) != '' || substr($rel, 0, 2) == '//') return $rel; | |
13 | |
14 /* queries and anchors */ | |
15 if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; | |
16 | |
17 /* parse base URL and convert to local variables: | |
18 $scheme, $host, $path */ | |
19 extract(parse_url($base)); | |
20 | |
21 /* remove non-directory element from path */ | |
22 $path = preg_replace('#/[^/]*$#', '', $path); | |
23 | |
24 /* destroy path if relative url points to root */ | |
25 if ($rel[0] == '/') $path = ''; | |
26 | |
27 /* dirty absolute URL */ | |
28 $abs = "$host$path/$rel"; | |
29 | |
30 /* replace '//' or '/./' or '/foo/../' with '/' */ | |
31 $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); | |
32 for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} | |
33 | |
34 /* absolute URL is ready! */ | |
35 return $scheme.'://'.$abs; | |
36 } | |
37 | 9 |
38 // XML Saves location - assumes it will be saves/ | 10 // XML Saves location - assumes it will be saves/ |
39 $data = []; | 11 $data = array(); |
40 $saves = glob("../saves/*.xml"); | 12 $saves = glob("../saves/*.xml"); |
41 if (is_array($saves)) | 13 if (is_array($saves)) |
42 { | 14 { |
43 foreach($saves as $filename) { | 15 foreach($saves as $filename) { |
44 $xml_string = file_get_contents($filename, FILE_TEXT); | 16 $xml_string = file_get_contents($filename, FILE_TEXT); |
50 if(array_key_exists($testName,$data)) { | 22 if(array_key_exists($testName,$data)) { |
51 // Key exists | 23 // Key exists |
52 array_push($data[$testName],$filename); | 24 array_push($data[$testName],$filename); |
53 } else { | 25 } else { |
54 // Key does not exist | 26 // Key does not exist |
55 $data[$testName] = [$filename]; | 27 $data[$testName] = array($filename); |
56 } | 28 } |
57 } | 29 } |
58 } | 30 } |
59 } | 31 } |
60 | 32 |