PHP如何回显多个输出

时间:2013-12-22 12:23:44

标签: php

我是编程新手,需要PHP帮助。我有一个用于解密字符串的代码。问题是它只显示函数中的解密第一个变量(decriptInfoDetails)。什么需要改变所以它还可以显示函数中的第二个和第三个变量?还有一种更好的方法可以做到这一点,例如,如果我有更多变量来解密说10或更多吗?我附上以下代码用于查看目的。希望有人可以帮助这个新手,并提前感谢。

    <?

        $privateKey = "xxxxx";
        $iv = "xxxxx";

        $keyPassword = "xxxxx";
        $ivPassword = "xxxxx";              

        function decriptInfoDetails($ciphertext_base64){
        global $privateKey,$iv;

        $ciphertext_dec = trim(base64_decode($ciphertext_base64));

        $plaintext_utf8_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey,
        $ciphertext_dec, MCRYPT_MODE_CBC, $iv);         

        return trim($plaintext_utf8_dec);
        }

        function encPass($ciphertext_base64){
        global $keyPassword,$ivPassword;

        $ciphertext_dec = trim(base64_decode($ciphertext_base64));

        $plaintext_utf8_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $keyPassword,
        $ciphertext_dec, MCRYPT_MODE_CBC, $ivPassword);

        return trim($plaintext_utf8_dec);
        }           

        function encAndDecPass($data){
        global $keyPassword,$ivPassword;

        $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $keyPassword, $data, MCRYPT_MODE_CBC, $ivPassword);
        $ciphertext_base64 = trim(base64_encode($encrypted));

        return  trim($ciphertext_base64);
        }

        echo decriptInfoDetails("D8D6OsHciT/rBfeNMGrwtQZegzDv02dTnotroNOe+Kk=","ojPlxa16CVhoLq8GP8d0h5l+Z+5GqFXSWXaX7GSXC/Q=1","zrJCOomZ4CJIeBTomAb9OGq2pQK17FBGqVNFdVawPB8=1"); 

    ?>

2 个答案:

答案 0 :(得分:1)

将函数的参数更改为数组。

<?
error_reporting(E_ALL);
$privateKey = "xxxxx";
$iv         = "xxxxx";

$keyPassword = "xxxxx";
$ivPassword  = "xxxxx";

function decriptInfoDetails($ciphertext_base64_ar)
{
    global $privateKey, $iv;

    $result = array();

    foreach ($ciphertext_base64_ar as $ciphertext_base64) {
        $ciphertext_dec = trim(base64_decode($ciphertext_base64));

        $plaintext_utf8_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey,
        $ciphertext_dec, MCRYPT_MODE_CBC, $iv);

        $result[]= trim($plaintext_utf8_dec);
    }

    return $result;
}
print_r(decriptInfoDetails(array(
    "D8D6OsHciT/rBfeNMGrwtQZegzDv02dTnotroNOe+Kk=",
    "ojPlxa16CVhoLq8GP8d0h5l+Z+5GqFXSWXaX7GSXC/Q=1",
    "zrJCOomZ4CJIeBTomAb9OGq2pQK17FBGqVNFdVawPB8=1"
)));

?>

注意:删除了未使用的功能。

答案 1 :(得分:0)

如果没有成为此问题的专家,并且只是为了尝试帮助目的,我认为在下面的代码结尾处,您在decriptInfoDetails函数内提供了太多参数,而在您的代码开头时只有一个。你应该只给一个而不是三个。

echo decriptInfoDetails("D8D6OsHciT/rBfeNMGrwtQZegzDv02dTnotroNOe+Kk=","ojPlxa16CVhoLq8GP8d0h5l+Z+5GqFXSWXaX7GSXC/Q=1","zrJCOomZ4CJIeBTomAb9OGq2pQK17FBGqVNFdVawPB8=1");