EnexoOnoma
EnexoOnoma

Reputation: 8836

Str_replace multiple strings in one variable?

How can I combine the two str_replace to one variable?

$putbhp = str_replace("cc,A","cc,0bhp,A",$whites);

$putbhp = str_replace("cc,M","cc,0bhp,M",$whites);

Upvotes: 1

Views: 580

Answers (1)

Phil
Phil

Reputation: 164871

$putbhp = str_replace(['cc,A', 'cc,M'], ['cc,0bhp,A', 'cc,0bhp,M'], $whites);

If you're stuck with an old version of PHP (< 5.4), substitute the array shorthand with array('val', 'val', 'etc')

Demo here - http://codepad.viper-7.com/3HKxV9

Upvotes: 3

Related Questions