Somenoob
Somenoob

Reputation: 27

PHP If string contains '+' change it to 'test'?

how might I be able to do this?

I'm familiar with the str operators, but am pretty unsure how might I be able to do this.

Logic test:

    If (string.contains == '+') {
string.change("test");
}

Basically what it's needed for:

it'll be used for a string that contains more then just a + e.g. hello+hello will change into -> hellotesthello

Upvotes: 0

Views: 93

Answers (2)

Ilan Frumer
Ilan Frumer

Reputation: 32357

$string = preg_replace('/\+/','test',$string);

Upvotes: 0

Jessica
Jessica

Reputation: 7005

if(strpos($string, '+') !== false){
   $string = 'test';
}

If you want to change the + into test you would use

$string = str_replace('+', 'test', $string);

Upvotes: 2

Related Questions