search
Homephp教程php手册php实现的简单压缩英文字符串的代码

php实现的简单压缩英文字符串的代码

Jun 13, 2016 pm 12:28 PM
pphpsuperiorcodeencryptioncompressioncopystringaccomplishofSimpleEnglish

PHP,适应于上帖简单加密后的密文

复制代码 代码如下:


//replacement来自上个版本的加密替换 

     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,通用格式

复制代码 代码如下:


#!/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         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         c = 0; 
        while(substr(str, i, 1)~/[0-9]/) { 
            c = c*10+substr(str, i, 1); 
            i++; 
        } 
        if(c         while(c--) str_out = str_out""substr(str, i, 1); 
    } 
    return str_out; 
}

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.