//==========$a,$b,$c全部为字符串==========
//例一
echo $str = str_replace('ac','M','bac abc dacf');
//输出 bM abc dMf
//==========$a,$b,$c全部为数组==========
//例二 $a,$b,$c数组成员个数相等
$a = Array('a1','a2');
$b = Array('b1','b2');
$c = Array('a1 c1 a1','a1 c2 a2');
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 Array ( [0] => b1 c1 b1 [1] => b1 c2 b2 )
//4
//例三 $a,$c数组成员个数相等,$a数组成员比$b数据成员个数多
$a = Array('a1','a2');
$b = Array('b1');
$c = Array('a1s c1s a1s','a1s c2s a2s');
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 Array ( [0] => b1s c1s b1s [1] => b1s c2s s )
//4
//例四 $a,$c数组成员个数相等,$a数组成员比$b数据成员个数少
$a = Array('a1');
$b = Array('b1','b2');
$c = Array('a1s c1s a1s','a1s c2s a2s');
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 Array ( [0] => b1s c1s b1s [1] => b1s c2s a2s )
//3
//例五
$a = Array('a1','a2');
$b = Array('b1','b2');
$c = Array('a1s c1s a1s','a1s c2s a2s','a1sa2s a2');
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 Array ( [0] => b1s c1s b1s [1] => b1s c2s b2s [2] => b1sb2s b2 )
//7
//==========$a,$b为数组,$c为字符串==========
//例六 $a,$b为数组,$c为字符串
$a = Array('a1','a2');
$b = Array('b1','b2');
$c = 'a1s c1s a1sa1sa2s a2';
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 b1s c1s b1sb1sb2s b2
//5
//例七
$a = Array('a1','a2');
$b = '';
$c = 'a1s c1s a1sa1sa2s';
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 s c1s sss
//4
//例八
$a = Array('a1','先生');
$b = '';
$c = 'a1s c1s 织梦先生s';
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 s c1s 织梦s
//2
//例九 这个例子有点意思
$a = Array('a1','先生','织梦s');
$b = '';
$c = 'a1s c1s 织梦先生sa';
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 s c1s a
//3
//例十 这个例子和上一个例子说明一个问题
$a = Array('a1','织梦s','先生');
$b = '';
$c = 'a1s c1s 织梦先生s';
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//输出 s c1s 织梦s
//2
//例十一 出错,证明这样是不允许的
$a = 'a1';
$b = Array('b1','b2');
$c = 'a1s c1s 织梦先生a1s';
$str = str_replace($a,$b,$c,$i);
print_r($str);
echo '<br>';
echo $i;
//提示出错 PHP Notice: Array to string conversion in E:\Test\test.php on line 6
//意思就是在$a为字符串时,$b也必须是字符串