//要存的html源码内容,支持换行,注意把单引号用\转移
$testStr = '
row 1, cell 1 | row 1, cell 2 |
row 2, cell 1 | row 2, cell 2 |
';
function randomStr($intLength)
{
$str = null;
$strPol = "abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol)-1;
for($i=0;$i
$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
}
return $str;
}
//定义随机字符串,作为变量名
function getCode($intLength)
{
$str = null;
$strPol = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$max = strlen($strPol)-1;
for($i=0;$i
$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
}
return $str;
}
function vbsEscape11($str)
{
return htmlspecialchars($str, ENT_QUOTES);
}
function vbsEscape($str)
{
$sublen=strlen($str);
$retrunString="";
for ($i=0;$i
{
if(ord($str[$i])>=127)
{
$tmpString=bin2hex(iconv("gb2312","ucs-2",substr($str,$i,2)));
//$tmpString=substr($tmpString,2,2).substr($tmpString,0,2);window下可能要打开此项
$retrunString.="%u".$tmpString;
$i++;
} else
{
$retrunString.="%".dechex(ord($str[$i]));
}
}
return $retrunString;
}
function mainFun($htmlStr)
{
$ax01 = getCode(4).randomStr(12);// '替换字符1
$ax02 = getCode(4).randomStr(12);// '替换字符2
$ax03 = getCode(4).randomStr(12);// '替换字符3
$ax04 = getCode(4).randomStr(12);// '替换字符4
$ax05 = getCode(4).randomStr(12);// '替换字符5
$ax07 = getCode(4).randomStr(12);// '变量名1
$ax08 = getCode(4).randomStr(12);// '变量名2
$ax09 = getCode(4).randomStr(12);// '变量名3
$ht01=str_replace("\r\n","",$htmlStr);
$ht01=vbsEscape($ht01);
$ht01=str_replace("-",$ax01,$ht01);
$ht01=str_replace("/",$ax02,$ht01);
$ht01=str_replace(".",$ax03,$ht01);
$ht01=str_replace("%",$ax04,$ht01);
$ht01=str_replace("_",$ax05,$ht01);
$ht01=str_replace("_",$ax06,$ht01);
$ht01=str_replace("_",$ax07,$ht01);
$ht01=str_replace("_",$ax08,$ht01);
$ht01=str_replace("_",$ax09,$ht01);
echo
'
'.$ax07.'=\''.$ht01.'\';
'.$ax07.'='.$ax07.'.replace(/'.$ax01.'/g, \'-\').replace(/'.$ax02.'/g, \'/\').replace(/'.$ax03.'/g, \'.\').replace(/'.$ax04.'/g, \'%\').replace(/'.$ax05.'/g, \'_\');
var '.$ax08.'=unescape('.$ax07.');
document.write('.$ax08.')
';
}
mainFun($testStr);
?>