如何替换 header 的所有字符
how to replace all characters of a header
我如何用真正的 php 函数 chr(rand(97,122))
替换所有 __Chr(__Rand(98,122))
和 __Chr(__Rand(97,122))
值,该函数以通用方式提供随机且具有相同参数这里是header :
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
您可以为此使用 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
我如何用真正的 php 函数 chr(rand(97,122))
替换所有 __Chr(__Rand(98,122))
和 __Chr(__Rand(97,122))
值,该函数以通用方式提供随机且具有相同参数这里是header :
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
您可以为此使用 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