如何用真正的php函数__Chr(__Rand(98,122))
替换所有__Chr(__Rand(97,122))
和chr(rand(97,122))
值,这些函数以通用方式提供随机和相同的参数,这里是标题:
Reply-To: __Reply-To
Bounces_to: __Bounce
Message-ID: <__Chr(__Rand(97,122))__Chr(__Rand(98,122)).__X-Mailer@__From_dn>
X-BFI: __Chr(__Rand(97,122))__Chr(__Rand(98,122))
From: __To
答案 0 :(得分:2)
您可以使用preg_replace_callback,即:
<?php
$header = <<< LOB
Reply-To: __Reply-To
Bounces_to: __Bounce
Message-ID: <__Chr(__Rand(97,122))__Chr(__Rand(98,122)).__X-Mailer@__From_dn>
X-BFI: __Chr(__Rand(97,122))__Chr(__Rand(98,122))
From: __To
LOB;
function charCallback($matches){
$charOne = (int)$matches[1];
$charTwo = (int)$matches[2];
return chr(rand($charOne,$charTwo));
}
echo preg_replace_callback('/__Chr\(__Rand\((\d+),(\d+)\)\)/', 'charCallback', $header);
<强>输出:强>
Reply-To: __Reply-To
Bounces_to: __Bounce
Message-ID: <uw.__X-Mailer@__From_dn>
X-BFI: jn
From: __To