-
Notifications
You must be signed in to change notification settings - Fork 1
/
color.php
48 lines (41 loc) · 1.09 KB
/
color.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
39
40
41
42
43
44
45
46
47
48
<?php
function hashUri($uri) {
return hash("md5",$uri) ;
}
function color($hash) {
return substr($hash,strlen($hash) -6, strlen($hash));
#return substr($hash,0, 6);
}
function getColorParts ($hexRGB) {
if (strlen($hexRGB) == 6) {
$rgb_dec = array (
"red" => hexdec(substr($hexRGB, 0, 2)),
"green" => hexdec(substr($hexRGB, 2, 2)),
"blue" => hexdec(substr($hexRGB, 4, 2)));
return $rgb_dec;
}
return false;
}
function checkIRI($iri){
#$pattern = "/(?<!\\)\\(?![\[\]\\\^\$\.\|\*\+\(\)QEnrtaefvdwsDWSbAZzB1-9GX]|x\{[0-9a-f]{1,4}\}|\c[A-Z]|)/";
#$isIRI = preg_match ($pattern, $iri);
#have to check the IRI validate regex again, but later
$isIRI = 1 ;
if (1 === $isIRI) {
return TRUE;
}
return FALSE;
}
$hexColor = null;
$iri = null;
$error = null;
if (!empty($_REQUEST['iri'])){
#check if URI is correct else message
$iri = $_REQUEST['iri'];
if (FALSE == checkIRI($iri)) {
$error = "No valid IRI is given";
}
$hash = hashUri($iri);
$hexColor = color($hash);
}
?>