PHP, adapted to the post-simple encryption of ciphertext
Copy the Code code as follows:
Replacement encryption replacement from the previous version
function Compress_func ($match) {return strlen ($match [0]). $match [0]{0};}
function Uncompress_func ($match) {return str_repeat ($match [2], $match [1]);}
function Compress ($STR) {
$i = 0;
$pattern = Array ();
while (Isset ($replacement {$i})) Array_push ($pattern, "/". $replacement {$i + +}. " {2,}/");
Return Preg_replace_callback ($pattern, "Compress_func", $str);
}
function Uncompress ($STR) {
Return Preg_replace_callback ("/(d+) (W)/", "Uncompress_func", $str);
}
?>
AWK, General format
Copy the Code code as follows:
#!/bin/awk
function compress (str, _argvend_, str_out, Str_len, I, S, l) {
Str_out = "";
Str_len = Length (str);
s = "";
L = 1;
for (i =1; I <= str_len; i++) {
if (substr (str, I, 1) = = = s) l++;
else {
if (s! = "") {
if (L > 1) str_out=str_out "" L
Str_out=str_out "" s;
}
s = substr (str, I, 1);
L = 1;
}
}
return str_out;
}
function uncompress (str, _argvend_, str_out, Str_len, I, c) {
Str_out = "";
Str_len = Length (str);
for (i =1; I <= str_len; i++) {
c = 0;
while (substr (str, I, 1) ~/[0-9]/) {
c = c*10+substr (str, I, 1);
i++;
}
if (c < 1) c = 1;
while (c--) str_out = Str_out "" substr (str, I, 1);
}
return str_out;
}
The above describes the User-agent string PHP implementation of the simple compression of the English string code, including the contents of the User-agent string, I hope that the PHP tutorial interested in a friend helpful.