source preg_replace_callbac data base64 a-z0-9 si function mime_type s

 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
$source = preg_replace_callback("#data:([^,]+)base64,([a-z0-9\=\/\+]+)#si", function ($m) {
$mime_type = strtolower(explode(";", $m[1])[0]);
if ($mime_type == 'application/x-font-woff') {
$name = "bin/".md5($m[2]).".woff";
file_put_contents("../www/static/css/".$name, base64_decode($m[2]));
return $name;
} elseif ($mime_type == 'font/opentype') {
$name = "bin/".md5($m[2]).".ttf";
file_put_contents("../www/static/css/".$name, base64_decode($m[2]));
return $name;
} elseif ($mime_type == 'image/gif') {
$name = "bin/".md5($m[2]).".gif";
file_put_contents("../www/static/css/".$name, base64_decode($m[2]));
return $name;
}
return $m[0];
}, $source);
$source = preg_replace("#/\*.*?\*/#si", "", $source);
$source = preg_replace("#\s+#si", " ", $source);
$source = preg_replace("#\s*:\s*#si", ":", $source);
$source = preg_replace("#s*\;\s*\}+#si", "}", $source);
$source = preg_replace("#\s*{\s*#si", "{", $source);
$source = preg_replace("#\s*}\s*#si", "}", $source);
$source = preg_replace("#\s*,\s*#si", ",", $source);
$source = preg_replace("#\s*;\s*#si", ";", $source);