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

前端之家收集整理的这篇文章主要介绍了php实现的简单压缩英文字符串的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

PHP,适应于上帖简单加密后的密文 <div class="codetitle"><a style="CURSOR: pointer" data="40722" class="copybut" id="copybut40722" onclick="doCopy('code40722')"> 代码如下:

<div class="codebody" id="code40722">
<?PHP
//replacement来自上个版本的加密替换 functioncompress_func($match){returnstrlen($match[0]).$match[0]{0};} functionuncompress_func($match){returnstr_repeat($match[2],$match[1]);} functioncompress($str){
$i=0;
$pattern=array();
while(isset($replacement{$i}))array_push($pattern,"/".$replacement{$i++}."{2,}/");
returnpreg_replace_callback($pattern,"compress_func",$str);
} functionuncompress($str){
returnpreg_replace_callback("/(d+)(w)/","uncompress_func",$str);
}
?>

AWK,通用格式 <div class="codetitle"><a style="CURSOR: pointer" data="32436" class="copybut" id="copybut32436" onclick="doCopy('code32436')"> 代码如下:
<div class="codebody" id="code32436">
#!/bin/awk
functioncompress(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,1)==s)l++;
else{
if(s!=""){
if(l>1)str_out=str_out""l
str_out=str_out""s;
}
s=substr(str,1);
l=1;
}
}
returnstr_out;
}
functionuncompress(str,c){
str_out="";
str_len=length(str);
for(i=1;i<=str_len;i++){
c=0;
while(substr(str,1)~/[0-9]/){
c=c*10+substr(str,1);
i++;
}
if(c<1)c=1;
while(c--)str_out=str_out""substr(str,1);
}
returnstr_out;
}

原文链接:https://www.f2er.com/php/29670.html

猜你在找的PHP相关文章