0
<?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

如何获得哈希作为回报?

4

1 回答 1

6

你把参数的顺序str_replace()弄错了:

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

正确的顺序是

  1. (数组)要搜索的字符串
  2. (数组)替换
  3. (数组)字符串,其中要替换
于 2013-02-12T18:26:15.947 回答