User-agent string PHP Implementation of simple compressed English string code

Source: Internet
Author: User
Tags uncompress
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.