我上次看见有人用str_replace  替换是可以写成数组的,,给点资料,连接来看看吧

解决方案 »

  1.   

    由 str_replace 函数声明
    mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count] )
    可知,替换是可以写成数组的类型 mixed 自然是包括 数组 的手册中已经给出了示例代码,不需要再找了吧?
    <?php
    // Provides: <body text='black'>
    $bodytag = str_replace("%body%", "black", "<body text='%body%'>");// Provides: Hll Wrld f PHP
    $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
    $onlyconsonants = str_replace($vowels, "", "Hello World of PHP");// Provides: You should eat pizza, beer, and ice cream every day
    $phrase  = "You should eat fruits, vegetables, and fiber every day.";
    $healthy = array("fruits", "vegetables", "fiber");
    $yummy   = array("pizza", "beer", "ice cream");$newphrase = str_replace($healthy, $yummy, $phrase);// Use of the count parameter is available as of PHP 5.0.0
    $str = str_replace("ll", "", "good golly miss molly!", $count);
    echo $count; // 2
    ?> 
      

  2.   

    看错了,原来我的意思是strtr这个函数实现的
      

  3.   

    $trans = array("hello" => "hi", "hi" => "hello");
    echo strtr("hi all, I said hello", $trans);
    hello all, I said hi