Replace multiple words with Str_Replace PHP 8 | Codexpress Programming Blog - Tutorials about, PHP, MySQL and Web Development

Replace multiple words with Str_Replace PHP 8

How to replace multiple synonyms with one specific word using PHP


$a = array( 'truck', 'vehicle', 'seddan', 'coupe' );
 
$str = 'Honda is a truck. Toyota is a vehicle. Nissan is a sedan. Scion is a coupe.';
echo str_replace($a,'car',str_replace('Lexus','Toyota',$str));

This will replace vehicle->car and so on

Demo http://ideone.com/0I37nX