1

好的,下面有一些 php 代码。

$user_pass = "
vortex90:OPFY4MB8
jimmy3:3M7ISWof
dave-ish-mental:YEnMMXua
cindybaby:rRHxrErp
claire-x:H4VrT8Xx
icemonster:ODId9N17
";

$token = 'token';    
$ex = explode("\r", $user_pass);

foreach ($ex as $info) {
   print "username=" . str_replace(":", "&password=", $info) . "&token=" . $token . "\n";
}

我想要 foreach() 做的是为每个爆炸显示

username=username&password=password&token=token

但下面是返回的内容。

vortex90&password=OPFY4MB8
jimmy3&password=3M7ISWof
dave-ish-mental&password=YEnMMXua
cindybaby&password=rRHxrErp
claire-x&password=H4VrT8Xx
icemonster&password=ODId9N17

为什么它没有按预期返回?欢迎所有答案。

4

1 回答 1

3

这对我有用,最好使用 PHP_EOL:

$token = "bla";
$user_pass = "
vortex90:OPFY4MB8
jimmy3:3M7ISWof
dave-ish-mental:YEnMMXua
cindybaby:rRHxrErp
claire-x:H4VrT8Xx
icemonster:ODId9N17
";

$explode = explode(PHP_EOL, $user_pass);

foreach($explode as $i) {
$replace_shit  = str_replace(array("\r","\n",":"), array("","","&password="), $i);
$user_info = "username=".$replace_shit."&token=".$token."<br>\n";

echo $user_info;
}

演示:http ://sandbox.onlinephpfunctions.com/code/02f6663f7fa69c158a90fde2ab421cf52a78f7ce

于 2013-02-15T23:25:52.467 回答