예제 #1
0
 public function testReplace()
 {
     $input = 'Ąbć dęfć';
     $this->assertEquals('Ąbć fółć', Str::replace($input, 'dęf', 'fół'));
     $this->assertEquals('Ąbź żółć', Str::replace($input, array('dęf' => 'fół', 'ć f' => 'ź ż')));
     $this->assertEquals('Ąbź żółć', Str::replace($input, array('dęf', 'ć f'), array('fół', 'ź ż')));
     $this->assertEquals('Ąbć mooć', Str::replace($input, array('dęf', 'ć f'), 'moo'));
 }
예제 #2
0
 /**
  * Wrapper for str_replace()
  * @return StrObject
  */
 public function replace($search, $replace = null)
 {
     if (is_array($search) && $replace === null) {
         $replace = array_values($search);
         $search = array_keys($search);
     }
     $value = Str::replace($this->value, $search, $replace);
     return new self($value);
 }