自己的加密脚本

时间:2013-02-12 18:23:52

标签: php arrays encryption hash passwords

<?php
   error_reporting(E_ALL ^ E_NOTICE);
   $string = "123456";
   $replace_from = array(
   "1",
   "2",
   "3",
   "4",
   "5",
   "6");
   $replace_to = array(
   "Al01",
   "Br20",
   "Ch03",
   "De40",
   "Ec05",
   "Fo60");
   $hashed = str_replace($string, $replace_from, $replace_to);
   echo "String: ". $string ."<br>";
   echo "Encrypted: ". $hashed ."<br>";
   echo "<br>";
   print_r($hashed);
?>

我得到了

Encrypted: Array

但我期待

Encrypted: Al01Br20Ch03De40Ec05Fo60

如何将哈希作为回报?

1 个答案:

答案 0 :(得分:6)

您的参数顺序为str_replace()错误:

$hashed = str_replace( $replace_from, $replace_to, $string );

正确的顺序是

  1. (数组)要搜索的字符串
  2. (数组)替换
  3. (数组)字符串,用于替换