忽略大小写,PHP替换2个单词

时间:2015-08-23 21:12:18

标签: php string replace case

我试图在一个字符串中互相替换2个单词,而忽略了他们的情况,但我似乎无法找到一种方法使其正常工作。请看一下我的代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<title>MySlide</title>

<body>

	<div id="container">
		Container
     <div id="big">
     	big
     </div>

     <div class="slides">

      <div class="thumb one" onclick="clickFunction()">
      	<img src="http://assets22.pokemon.com/assets/cms2/img/pokedex/full/007.png">
      </div>
      <div class="thumb 2"onclick="clickFunction2()">
      <img src="http://cdn.bulbagarden.net/upload/thumb/f/fb/143Snorlax.png/250px-143Snorlax.png">
      </div>
      <div class="thumb 3"onclick="clickFunction3()">
      <img src="http://img2.wikia.nocookie.net/__cb20140410200831/pokemon/images/0/02/025Pikachu_Dream.png">
      </div>
      <div class="thumb 4"onclick="clickFunction4()">
      <img src="http://pre03.deviantart.net/27f2/th/pre/f/2012/218/0/7/_004_charmander___1st_attempt_sugimori_style_by_white__flame-d59zqwh.png">
      </div>





     </div>


          </body>

预期结果:&#34;我和你&#34;;

实际结果:&#34;你和你&#34 ;;

编辑:实际上并不包括忽略案例。

2 个答案:

答案 0 :(得分:2)

这很简单,只需使用str_ireplace

$text = "YoU and mE";
$from = array('you', 'me', '__TMP__');
$to   = array('__TMP__', 'you', 'me');
$text = str_ireplace($from, $to, $text);

答案 1 :(得分:0)

检查:http://php.net/manual/en/function.strtr.php

$trans = array("you" => "me", "me" => "you");
echo strtr("you and me", $trans);